TS2304:找不到名称<class name =“”>

时间:2019-02-01 08:20:26

标签: typescript vuejs2 nuxt.js

我将nuxt.js更新为最新版本(2.4.2)。当我更新时,当我执行 npm run dev 时,它将返回找不到名称,但是在nuxt.js 1中却找到了。我的代码如下:

资产/脚本/b.ts

export default class B {}

资产/脚本/a.ts

import B from "assets/scripts/b"

tsconfig.json

{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "es2015"],
"module": "es2015",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": ".",
"types": ["node"],
"typeRoots": [
  "node_modules/@types",
  "types/*"
]
},
"compileOnSave": true
}

模块: typescript.js

module.exports = function () {
// Add .ts & .tsx extension to Nuxt

this.nuxt.options.extensions.push('ts', 'tsx')

// Extend webpack build
this.extendBuild(config => {
// Add TypeScript
config.module.rules.push({
  test: /\.tsx?$/,
  loader: 'ts-loader',
  options: { appendTsSuffixTo: [/\.vue$/] }
})

// Add .ts extension in webpack resolve
if (! config.resolve.extensions.includes('.ts')) {
  config.resolve.extensions.push('.ts')
}

// Add .tsx extension in webpack resolve
if (! config.resolve.extensions.includes('.tsx')) {
  config.resolve.extensions.push('.tsx')
}
})
}

1 个答案:

答案 0 :(得分:1)

您应该在nuxt 2.4上使用nuxt-ts。 请参阅发行说明https://github.com/nuxt/nuxt.js/releases/tag/v2.4.0