启用“装饰的实验支持"与"tsify"在因果报应中 [英] Enable "Experimental support for decorators" with "tsify" in karma
问题描述
我正在使用tsify(用于浏览器的插件)在业力单元测试期间转换我的代码.
I'm using tsify, a plugin for browserify, to transpile my code during karma unit tests.
运行测试时出现这种错误:
I get this sort of erro when I run my tests:
TypeScript错误:src/app/emailLogin/emailLogin.component.ts(14,14):错误TS1219:对装饰器的实验性支持是一项功能,在将来的发行版中可能会更改.设置"experimentalDecorators"选项以删除此警告.
TypeScript error: src/app/emailLogin/emailLogin.component.ts(14,14): Error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
如何在我的karma.config.js中指定的browserify/tsify中启用experimentalDecorators
How do enable experimentalDecorators in browserify/tsify, which are specified in my karma.config.js
这是我的karma.config.js:
Here is my karma.config.js:
module.exports = function(config) {
config.set({
browsers: ['Chrome'],
frameworks: ['jasmine', 'browserify', 'es6-shim'],
files: [
'src/**/*.spec.ts'
],
preprocessors: {
'**/*.ts': ['browserify']
},
browserify: {
debug: true,
plugin: ['tsify'],
transform: ['browserify-shim']
}
});
};
这是我的gulp文件(我认为这没关系)
Here is my gulp file (I think this doesn't matter)
var gulp = require('gulp');
var Server = require('karma').Server;
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
/**
* Watch for file changes and re-run tests on each change
*/
gulp.task('tdd', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js'
}, done).start();
});
gulp.task('default', ['tdd']);
推荐答案
有两个编译器选项:
--emitDecoratorMetadata
--experimentalDecorators
通常,将在项目的tsconfig.json
文件中启用它们(tsify
将搜索并加载tsconfig.json
):
Typically, they would be enabled in your project's tsconfig.json
file (tsify
will search for and load the tsconfig.json
):
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5"
},
"files": []
}
如果由于某种原因未使用tsconfig.json
文件,则可以在Karma中的browserify
插件配置中启用它们(请注意数组中的数组):
If, for some reason, you are not using a tsconfig.json
file, they can be enabled in the browserify
plugin's configuration in Karma (note the array within the array):
browserify: {
debug: true,
plugin: [['tsify', {
emitDecoratorMetadata: true,
experimentalDecorators: true
}]],
transform: ['browserify-shim']
}
它们也可以通过命令行启用:
And they can be enabled via the command line, too:
browserify -p [tsify --emitDecoratorMetadata --experimentalDecorators] main.ts > bundle.js
这篇关于启用“装饰的实验支持"与"tsify"在因果报应中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!