不能 运行 带有装饰器的打字稿代码
Can't run typescript code with decorators
我有这两个简单的文件,但每次我尝试 运行 testClass.ts 时,我都会收到此错误:
PS C:\Deno\pancakes> deno run testClass.ts
Compile file:///C:/Deno/pancakes/testClass.ts
error: TS1219 [ERROR]: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
name: string;
~~~~
at file:///C:/Deno/pancakes/testClass.ts:5:5
testClass.ts
import { notNull } from "./mod.ts";
class Person {
@notNull
name: string;
constructor(name: string) {
this.name = name;
}
}
let newPerson = new Person("");
mod.ts
export function notNull(target: any, propertyKey: string) {
console.log(target, propertyKey);
}
我已经在 VSCode 中启用了 experimentalDecorators 选项,创建 tsconfig.json 和所有内容,但仍然不能 运行 程序。我没有在 VSCode 中显示错误,但不能 运行.
编辑: this is what happens
使用 deno 你需要明确指定你的 tsconfig,
> deno run -c tsconfig.json testClass.ts
https://deno.land/manual/getting_started/typescript#custom-typescript-compiler-options
我有这两个简单的文件,但每次我尝试 运行 testClass.ts 时,我都会收到此错误:
PS C:\Deno\pancakes> deno run testClass.ts
Compile file:///C:/Deno/pancakes/testClass.ts
error: TS1219 [ERROR]: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
name: string;
~~~~
at file:///C:/Deno/pancakes/testClass.ts:5:5
testClass.ts
import { notNull } from "./mod.ts";
class Person {
@notNull
name: string;
constructor(name: string) {
this.name = name;
}
}
let newPerson = new Person("");
mod.ts
export function notNull(target: any, propertyKey: string) {
console.log(target, propertyKey);
}
我已经在 VSCode 中启用了 experimentalDecorators 选项,创建 tsconfig.json 和所有内容,但仍然不能 运行 程序。我没有在 VSCode 中显示错误,但不能 运行.
编辑: this is what happens
使用 deno 你需要明确指定你的 tsconfig,
> deno run -c tsconfig.json testClass.ts
https://deno.land/manual/getting_started/typescript#custom-typescript-compiler-options