在您需要了解TypeScript的
emitDecoratorMetadata
标志之前,TypeScript编译器会对Metadata Reflection API进行填充,并为已转换的TypeScript代码添加特殊的装饰器定义.Aurelia的@autoInject()装饰器使用TypeScript的装饰器创建的类型元数据,并以与@inject(...)装饰器相同的方式将其应用于类.
尝试如下,您需要启用compilerOptions
类型脚本中的新选项.
TS配置:
{ "version": "1.5.1", "compilerOptions": { "target": "es5", "module": "amd", "declaration": false, "noImplicitAny": false, "removeComments": false, "noLib": true, "emitDecoratorMetadata": true }, "filesGlob": [ "./**/*.ts", "!./node_modules/**/*.ts" ], "files": [ // ... ] }
文章的片段截图:
关于emitDecoratorMetadata的文章:
http
: //blog.durandal.io/2015/05/06/getting-started-with-aurelia-and-typescript/ http://www.danyow.net/inversion-of-control-with-奥里利亚部分-2 /
可用类型脚本选项:https:
//github.com/Microsoft/TypeScript/wiki/Compiler-Options
您可以使用Gulp-Typescript以及Gulp选项来完成
选项:https://github.com/ivogabe/gulp-typescript#options
GitHub问题主题:https://github.com/ivogabe/gulp-typescript/issues/100
Gulp Code Snippet:gulp.task('build-ts',[],function(){
return gulp.src(paths.typescript) .pipe(plumber()) .pipe(changed(paths.output, {extension: '.js'})) .pipe(sourcemaps.init()) .pipe(ts({ declarationFiles: false, noExternalResolve: true, target: 'es5', module: 'commonjs', emitDecoratorMetadata: true, typescript: typescript })) .pipe(sourcemaps.write()) .pipe(gulp.dest(paths.output)); });