[英]How to configure TypeScript to throw an error/warning for incorrect import statement?
I am working on converting a large application from JavaScript (Backbone and Angular 1) to TypeScript. 我正在将大型应用程序从JavaScript(主干和Angular 1)转换为TypeScript。 When we convert a file that is used by other files we understand that we have to update the import statements in those other JavaScript files so that it imports the new TypeScript file correctly.
当我们转换其他文件使用的文件时,我们了解到我们必须更新那些其他JavaScript文件中的import语句,以便它正确导入新的TypeScript文件。 Our syntax update in fake-file.js is as follows.
我们在fake-file.js中的语法更新如下。
Before: import OurService from 'our.service';
之前:
import OurService from 'our.service';
After: import { OurService } from 'our.service';
之后:
import { OurService } from 'our.service';
I understand that this is an easy change but TypeScript is new to many developers and there have been problems with people missing some of these import statements or forgetting to change them all together resulting in some issues during runtime. 我知道这是一个容易的更改,但是TypeScript对于许多开发人员来说是新手,而且人们会遗漏某些导入语句或忘记将它们全部更改在一起而导致运行时出现问题的问题。 I have looked into compiler options but I do not see any that would fix this issue but I could be misinterpreting them.
我已经研究了编译器选项,但是看不到能解决此问题的任何选项,但是我可能会误解它们。
Question: Is there a way to configure the compiler (or a Visual Studio Code plugin) to throw a warning or an error to prevent this from happening? 问题:有没有一种方法可以配置编译器(或Visual Studio Code插件)以发出警告或错误以防止这种情况发生?
I assume that I understood your requirement and possibly you need to adapt a linting process and consequently I would suggest the following tools (which I also use in my project): 我假设我了解您的要求,可能您需要调整起毛过程,因此,我建议使用以下工具(我也在项目中使用过):
rules configuration
and configure the ES rules for your project. rules configuration
然后为您的项目配置ES规则。 There are some import
related rules too. import
相关的规则。 PS: Feel free to add your comments.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.