【问题标题】:Can't run typescript code with decorators无法使用装饰器运行打字稿代码
【发布时间】:2020-09-18 09:23:01
【问题描述】:

我有这两个简单的文件,但每次我尝试运行 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

【问题讨论】:

    标签: typescript decorator deno typescript-decorator


    【解决方案1】:

    使用 deno 你需要明确指定你的 tsconfig,

    > deno run -c tsconfig.json testClass.ts
    

    https://deno.land/manual/getting_started/typescript#custom-typescript-compiler-options

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 2020-12-24
      • 2020-01-02
      • 2019-07-29
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2023-01-04
      相关资源
      最近更新 更多