-
Notifications
You must be signed in to change notification settings - Fork 12.8k
emitDecoratorMetadata causes runtime errors by referencing type-only imports with namespaces #42624
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
Comments
I could be convinced that this should be a compile-time error rather than emitting Object. Thoughts? |
It seems at first glance like a good idea to report an error, but why should importing the type (only) of a class be any different than importing an interface and using the exact same syntax. Also, this works just fine: import type { Services } from './services';
type S = Services.Service;
declare const decorator: any;
export class Main {
@decorator()
field: S;
} So if we can use an alias or an interface, why not an I think we should treat a type-only import the same way we do an interface or type alias and just emit |
Not sure I understand though, why should it be a compile-time error? |
I guess it depends on how important it is for the metadata to be as complete as it could be. The thought is simply that using |
Well, in my use case I'm importing a package using a type-only import to make sure it doesn't get bundled, since I want the bundle to be minimal. So I definitely don't want to change it to a regular import. |
Bug Report
Related to #37672 and #39337 - seems this bug still happens if class is wrapped by a namespace.
🔎 Search Terms
emitDecoratorMetadata, type-only imports, decorators
🕗 Version & Regression Information
Typescript 4.1.3, Typescript 4.2.0 beta
⏯ Playground Link
Workbench Repro
💻 Code
🙁 Actual behavior
Typescript will reference "Services.Service" even though it's not imported (only the type was). This will crash in runtime:
🙂 Expected behavior
Should not reference non imported classes:
The text was updated successfully, but these errors were encountered: