代码之家  ›  专栏  ›  技术社区  ›  Agent Droid

TS2304:找不到名称<类名>

  •  0
  • Agent Droid  · 技术社区  · 7 年前

    我把nuxt.js更新到最新版本(2.4.2)。当我更新时它会返回 找不到名称 当我这样做的时候 NPM运行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
    }
    

    模块: 类型脚本.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 回复  |  直到 7 年前
        1
  •  1
  •   Aldarund    7 年前

    您应该将nuxt ts与nuxt 2.4一起使用。 请参阅发行说明 https://github.com/nuxt/nuxt.js/releases/tag/v2.4.0