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
[consistent-type-import] flags non-type-only imported type as a value import when used in a decorator #3108
Comments
This is something I didn't know about typescript's decorator metadata. If I write this code: declare function Component(...args: any[]): any;
declare function namespace(...args: any[]): any;
@Component
export default class Comp {
@namespace('stuff').Action('fetch') private readonly fetchStuff!: ActionMethod;
} Then TS will see the value does not exist in scope, and attempt to maybe reference the value: __metadata("design:type", typeof (_a = typeof ActionMethod !== "undefined" && ActionMethod) === "function" ? _a : Object) If I add an import to a class (eg If I declare a class within the file ( __metadata("design:type", ActionMethod) If I declare a type within the file, TS will emit code depending on what the type is:
So far this is all well and good - TS can and should use the information from within the module to emit code. If, however, I import a type ( __metadata("design:type", Function) Which is really surprising - it's the first time I've seen it use type information from an imported thing thing to change the emitted code. This is obviously not really compatible with non-type-aware tools that work in an isolated model. |
Wow that is very interesting. Thank you for linking the playgrounds and discussion. I learned a lot about how TypeScript emits decorator metadata. In this case, what should be the solution in vue class components? |
it seems like a bug in the vue tooling (or whatever tooling it's built on top of). There is a separate bug in the lint rule because it does not understand that TS understands that the imported type is a type reference only. I don't know if we can fix this, however, because it would require using type information. |
I'm going to go ahead and mark this as non-actionable since it's a bug in other packages:
Please post back if you have a proposal for how we could solve this issue in typescript-eslint |
As a continuation from #2972 (comment), I was wondering if @bradzacher would be able to comment on whether or not vuejs/vue-cli#3145 (comment) is a bug in vue or in typescript-eslint
The text was updated successfully, but these errors were encountered: