-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
noUnusedLocals not recognizing imports required by the declaration emitter #21673
Comments
Duplicate of #9944. Please see the explanation of the current behavior in #9944 (comment). The fix is tracked by #9944. A workaround would be to add a type assertion using |
@mhegazy thank you for your quick response providing a workaround! I think this issue can be closed as a duplicate now?
(HasProductsMixin(Model) as { new(): Model & { readonly products: Product[] } }) Uff, that's a rather ugly workaround, to be honest. What if the mixin class adds several additional fields and method? I don't want to repeat them in every place where I am consuming the mixin. Looks like there is a simple solution though: // in types.ts
export interface HasProducts {
readonly products: Product[];
}
// in main.ts
export class Repo extends
HasProductsMixin(Model) as { new(): Model & HasProducts })
{
} It makes me wonder: is it possible to modify I tried the following but it's not enough (I still need your workaround to suppress noUnusedLocals error): export function HasProductsMixin(superClass: any) {
return class extends superClass implements HasProducts {
get products() : Product[] {
return [{name: 'Pen'}];
}
}
} (Strangely enough, the compiler does not complain about the fact that my original "main.ts" is not importing |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.8.0-dev.20180206
Search Terms:
Code
types.ts
main.ts
Compiler invocation:
Expected behavior:
Code compiles with no errors/warnings.
Actual behavior:
When I remove the offending import of
Product
, I receive the following error instead:Playground Link:
Sorry, I don't know how to create a playground requiring two source files :(
Related Issues:
The text was updated successfully, but these errors were encountered: