-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
design:type wrong for enum values #1160
Comments
@kdy1 Any news regarding this issue ? We have a similar problem that's preventing our team from switching to swc. We're using https://github.com/RobinBuschmann/sequelize-typescript and decorators are a problem for us right now. @Column
status: TProcessingStates; TSC: __decorate([
decorators_1.Groups([{ operation: 'read' }, { operation: 'write' }]),
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Collage.prototype, "status", void 0); SWC: Reflect.metadata("design:type", typeof _mediaManager.TProcessingStates === "undefined" ? Object : _mediaManager.TProcessingStates) Switching to swc would be a game changer for our team. |
@Exilz I'll fix this soon. I expect today or tomorrow (It's almost 11 PM here, so...) |
swc_ecma_transforms: - Emit proper typename for `design:type` used with enum. (#1160)
Fixed it. May I list your company on the site as swc user after the migration? |
@kdy1 I need to ask the CEO permission but I guess we'd be happy to be listed on the website ! EDIT: nevermind, I just realized you have a CI that's compiling it right now. |
@Exilz I'm now in progress of publishing. Github actions will publish new version. Oh. I noticed that github updates comments real-time. |
@kdy1 thanks a lot for the update. I'm still in the process of refactoring our code, but it looks like we're one step closer to migrating to swc. However, I noticed a couple of things :
import { TPublicationStatus } from '../publicationStatus';
class MyClass {
@Column
publicationStatus: TPublicationStatus;
} which compiles to _dec31 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", typeof _publicationStatus.TPublicationStatus === "undefined" ? Object : _publicationStatus.TPublicationStatus)
@Column
type: 'reps' | 'time'; which compiles to _dec24 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", void 0) This is also true when declaring the type separately and not directly in the class. Should I open a new issue ? Or two ? |
I'll just reopen this. Evaluating deps is not hard, but I'm not sure about the api change. |
@kdy1 I understand what you mean, this is quite a big change for the project as a whole. If this isn't implemented, you'd need to document it and make sure people are aware of this because it's quite "sneaky", and the errors it can generate when running your app won't make sense to most people. Maybe that's something the maintainers need to discuss further. |
I don't think it's sneaky. Why it's sneaky? |
Well, because something that's working within a single file will break when using imports. |
I believe this single file limitation will be a deal breaker for most people interested in SWC. If SWC can't be a transparent replacement for TSC, there will be just very few use cases where it will be used. |
I'm actively working on the type system, which will allow any transforms requiring type informations. Even though the issue can be fixed by simple hack, I'm not sure if it's correct way to go. It requires lots of opinionated approach. |
Would appreciate a simple hack first (or as an option) since type system is a long way to go. |
@Exilz No. I don't have one. |
I have questions regarding the issue. For the context, I want to implement this for the next version but this is fairly complex, mainly due to circular imports. To support it correctly, loader abstraction and a caching layer are required. So my first question is
It already have loader abstraction and a caching layer, so it would be easier. Also, I'm not sure about the api. I think flags like
If not, please feel free to tell me. |
@kdy1 We're not using spack. Our setup is fairly simple so using only the CLI is enough for us. The deps flag / includeDeps option would be awesome. I'm just wondering if it should be enabled by default. |
Is |
@sunnylqm No. The purpose of the option is to prevent breaking things. |
Compiling one by one is always a compromise for babel. If swc aims to work the same way as tsc then why not. Shouldn't swc eventually become a full feature drop in replacement? |
We can try some alpha versions to see if it can solve some problems |
@kdy1 hello and thanks for the awesome product! |
I think this can be fixed without the type checker. |
Does this work for |
@kdy1 thanks for the reply. Just checked, the project has no errors when running tsc with --isolatedModules switch. Of course, if this can be fixed, it will help a great deal to move our project to use swc. |
Encountering the same issue with sequelize-typescript, everything else is working perfectly but without Sequelize we can't run the app or |
See if this typeorm sidestep I made is somehow portable to sequelize. Essentially there were infered enum types that did not work and needed to be explicitly set |
Thanks, it did actually prevent one error from popping up, I'll see if applying this to all enum types solves the issue |
Amazing, this solved all the issues. Somehow tsc infers correct types when building but swc didn't, but by giving explicit types to Sequelize it works without issue. Thank you! |
What solution are you referring to? I do not see anything in this thread. I have the same issues with TypeOrm. |
For me it was to explicitly set the types, it seems like there's a problem inferring the type when built with I'm not sure if TypeORM uses a different format but setting the type explicitly in the decorator solved any Sequelize issues. |
Just wanna chime in that I ran into what I think is the same issue. I have a multi-project setup where projects A, and B references enums in project C (a shared library) through tsconfig paths. The enums work fine when using ts-loader (webpack) but when switching to SWC and swc-loader the enums are undefined at runtime. This is a bit of a bummer since the speed gains I got from SWC were amazing, but had to switch back to ts-loader for now. Thank you for all the hard work on this! Looking forward to switching over when this is fixed. |
+1 |
Closing as we are not going to implement |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
In TSC, when you have an enum type, the base enum type is set as design:type.
SWC is setting the enum object itself.
Input code
Config
Expected behavior
A clear and concise description of what you expected to happen.
TSC:
SWC:
The text was updated successfully, but these errors were encountered: