在项目的根目录中使用以下tsconfig.json
,我可以对experimentalDecorators
下的所有我的源文件使用没有警告的装饰器(注意src
选项):
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"removeComments": true,
"noLib": false,
"sourceMap": false,
"rootDir": "./src",
},
"exclude": [
"dist",
"node_modules",
"test/**/*",
]
}
但是,由于排除了 test文件夹,因此在测试用例(即test/my-component.spec.ts
)中会收到很多警告:
import 'mocha';
import { expect } from 'chai';
describe('MyComponent', () => {
it('decorators works', async () => {
@MyDecorator()
class TestClass () {}
// Test logic here...
});
});
对装饰器的实验支持是一项功能,将来的发行版中可能会对其进行更改。设置'experimentalDecorators'选项`以删除此警告。
如何抑制测试文件的工作?