Nuxt Typescript tsconfig 类型不起作用

发布于 2025-01-18 20:14:14 字数 1626 浏览 1 评论 0原文

尝试将 Nuxt 项目从 JS 迁移到 TS。在启用 Vetur 插件的 VS Code 中工作。

项目运行良好,但我无法使用 tsconfig.json 类型字段设置全局变量 hionts。

所以这是 tsconfig.json 文件:

  "compilerOptions": {
    "strictPropertyInitialization": false,
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "esnext",
      "esnext.asynciterable",
      "dom"
    ],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": [
      "@nuxt/types",
      "@types/node",
      "@nuxtjs/axios",
      "@nuxtjs/toast",
      "@nuxtjs/i18n",
      "vue-js-modal",
      "vue-meta",
      "vue-router",
      "nuxt-i18n"
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ],
  "include": [
    "**/*.ts",
    "**/*.vue",
    "vue-shim.d.ts"
  ]
}

这是组件:

<script lang='ts'>
import { Zlaggable } from '@/types/zlaggables/Zlaggable'
import { Component, mixins } from 'nuxt-property-decorator'
import UtilMixin from '@/assets/ts/UtilMixin'

@Component({
  name: 'ZlaggableHeaderCopyComponent'
})
export default class ZlaggableHeaderCopy extends mixins(UtilMixin) {
  mounted() : void {
    this.$toast.success("jj")
  }
  ...

在此处输入图像描述

我没有在 $toast 上提出方法和属性建议,而是出现了如图所示的错误。 $toast 实际上可以工作,但是 tsconfig.json 中的类型声明什么也没做,或者我犯了一些设置错误

Trying to migrate Nuxt project from JS to TS. Working in VS Code with Vetur plugin enabled.

Project works well, but I can't setup global variables hionts with tsconfig.json types field.

So here is tsconfig.json file:

  "compilerOptions": {
    "strictPropertyInitialization": false,
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "esnext",
      "esnext.asynciterable",
      "dom"
    ],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": [
      "@nuxt/types",
      "@types/node",
      "@nuxtjs/axios",
      "@nuxtjs/toast",
      "@nuxtjs/i18n",
      "vue-js-modal",
      "vue-meta",
      "vue-router",
      "nuxt-i18n"
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ],
  "include": [
    "**/*.ts",
    "**/*.vue",
    "vue-shim.d.ts"
  ]
}

and here is component:

<script lang='ts'>
import { Zlaggable } from '@/types/zlaggables/Zlaggable'
import { Component, mixins } from 'nuxt-property-decorator'
import UtilMixin from '@/assets/ts/UtilMixin'

@Component({
  name: 'ZlaggableHeaderCopyComponent'
})
export default class ZlaggableHeaderCopy extends mixins(UtilMixin) {
  mounted() : void {
    this.$toast.success("jj")
  }
  ...

enter image description here

Instead of methods and property suggestions on $toast I have an error like on the image. The $toast actually works, but the declaration of types in tsconfig.json just do nothing or I did some setup mistake

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文