首页 文章

Vue js 2.5.2&typescript升级错误

提问于
浏览
2

我正在尝试使用typescript 2.5.3将vue js升级到2.5.2 .

这是我的index.ts文件:

import Vue from 'vue'

var app = new Vue({
    el: '#app',
    data: {
        message: 'Hello Vue!'
    }
})

这是我的tsconfig.json

{
  "compilerOptions": {
    "outDir": "./wwwroot/build/",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "lib": [
      "dom",
      "es5",
      "es2015.promise"
    ],
    "types": [
      "vue-typescript-import-dts"
    ],
    "experimentalDecorators": true
  },
  "include": [
    "Features/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

这是错误消息:

C:\ dev \ proj \ src \ Proj.Web \ node_modules \ vue-typescript-import-dts \ index.d.ts(3,36)中的错误:错误TS2304:找不到名称'Vue' .

我的设置与vue js 2.4一起工作正常 .

我删除 "allowSyntheticDefaultImports": true, as said here

以前,我们已经建议在所有地方使用ES样式导入(从'vue'导入Vue)和“allowSyntheticDefaultImports”:tsconfig.json中为true . 新的类型将正式转换为ES样式的导入/导出语法,因此不再需要配置,并且用户在所有情况下都需要使用ES样式的导入 .

有人看到我错过了吗?

1 回答

  • 2

    我刚刚在VSCode中启动了一个新文件夹,我有几点意见 .

    NPM上的Vue包中包含类型信息,因此您无需为Vue获取其他类型(即不要从NPM中获取 @types/vue ) .

    "dependencies": {
        "vue": "^2.5.2"
    }
    

    只有vue包,没有部分:

    "types": [
      "vue-typescript-import-dts"
    ],
    

    我可以使用您的示例代码编译所有内容 .

    全部细节......

    的package.json

    {
        "name": "sample-vue",
        "private": true,
        "dependencies": {
            "vue": "^2.5.2"
        }
    }
    

    tsconfig.json

    {
        "compilerOptions": {
            "outDir": "./wwwroot/build/",
            "noImplicitAny": false,
            "noEmitOnError": true,
            "removeComments": false,
            "sourceMap": true,
            "target": "es5",
            "module": "es2015",
            "moduleResolution": "node",
            "lib": [
                "dom",
                "es5",
                "es2015.promise"
            ],
            "experimentalDecorators": true
        },
        "include": [
            "*.ts"
        ],
        "exclude": [
            "node_modules",
            "wwwroot"
        ]
    }
    

    app.ts

    import Vue from 'vue'
    
    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!'
        }
    })
    

相关问题