【问题标题】:Decorators must precede the name and all keywords of property declarations装饰器必须在属性声明的名称和所有关键字之前
【发布时间】:2021-09-29 08:39:43
【问题描述】:

我在打字稿文件中创建了一个名为@Inject 的装饰器,就像这样

export class A{
    @Inject()
    private b!: string

    @Inject()
    private c!: string
}

但是 vscode 告诉我有错误

export class A{
    @Inject()
    private b!: string

    @Inject() //error : Decorators must precede the name and all keywords of property declarations.
    private c!: string
}

但是当我执行 TSC 命令时,终端并没有显示任何错误。

最奇怪的是,当我以分号结尾时,错误消失了。

export class A{
    @Inject()
    private b!: string ;

    @Inject()
    private c!: string ;
}

【问题讨论】:

    标签: node.js typescript decorator


    【解决方案1】:

    您需要搜索您的 Typescript 版本并将其更改为您当前的工作区版本,而不是当前是开发版本的 vscode typescript 版本。

    >Typescript: Version之后的第一次搜索

    你可以选择当前工作区版本

    您也可以点击打字稿版本的右下角,将其更改为您当前的工作区版本。

    【讨论】:

      【解决方案2】:

      您必须在 Visual Studio 代码中更改版本打字稿。对我来说,打字稿版本是 4.3.2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-04
        • 2021-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-16
        • 1970-01-01
        • 2014-12-25
        相关资源
        最近更新 更多