简体   繁体   English

在 Angular2 或 NativeScript 中使用 Typescript 2 "noUnusedLocals"

[英]Using Typescript 2 "noUnusedLocals" with Angular2 or NativeScript

I'd like to enforce the new noUnusedLocals of Typescript 2.0 in my applications but all my functions that are references from the HTML are tagged as "never used" and are marked as errors.我想在我的应用程序中强制使用 Typescript 2.0 的新noUnusedLocals ,但是我所有从 HTML 引用的函数都被标记为“从未使用”并被标记为错误。

example:例子:

HTML HTML

<button ng-click="onButtonClick()">Upload</button>

Typescript (inside the Component Class)打字稿(在组件类中)

private onButtonClick(): void      //'onButtonClick' is declared but never used
{
    console.log('onButtonClick');
}

Is there a way to either silent these errors for specific functions or reference the HTML file so typescript knows they are used?有没有办法为特定功能消除这些错误或引用 HTML 文件以便打字稿知道它们被使用? I would really like to keep this functionality for code maintenance.我真的很想保留此功能以进行代码维护。

尝试将您的函数标记为public (它应该是),并且因为类是导出的并且函数是公共的,所以 TS 不应该抱怨它被使用了。

public onButtonClick(): void ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM