WebStorm 2023.1.2 doesn't recognize defineProps, defineEmits, computed etc. in a TypeScript project in Nuxt 3

huangapple go评论65阅读模式
英文:

WebStorm 2023.1.2 doesn't recognize defineProps, defineEmits, computed etc. in a TypeScript project in Nuxt 3

问题

以下是翻译好的内容:

正如标题所说,我正在使用TypeScript和<script setup>组合API语法在Nuxt 3项目上进行编程。该项目具有标准化的tsconfig.json

{
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "strict": true,
    "esModuleInterop": true,
    "types": ["@types/node"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

但是,WebStorm在其2023.1.2版本中仍然在自动导入的组合API函数上引发错误,错误消息如下:

tsconfig.json中未包含相应文件

这里有什么问题?我可以做什么来修复它?

我添加了一个标准化的ts.json配置并设置了项目,它不应该有错误。

英文:

As the headline says, I've programming on a Nuxt 3 project with TypeScript & &lt;script setup&gt; composition API syntax. The project has a standardized tsconfig.json:

{
  &quot;extends&quot;: &quot;./.nuxt/tsconfig.json&quot;,
  &quot;compilerOptions&quot;: {
    &quot;target&quot;: &quot;esnext&quot;,
    &quot;module&quot;: &quot;esnext&quot;,
    &quot;noImplicitAny&quot;: true,
    &quot;moduleResolution&quot;: &quot;node&quot;,
    &quot;strict&quot;: true,
    &quot;esModuleInterop&quot;: true,
    &quot;types&quot;: [&quot;@types/node&quot;]
  },
  &quot;include&quot;: [&quot;src/**/*&quot;],
  &quot;exclude&quot;: [&quot;node_modules&quot;]
}

But WebStorm in its 2023.1.2 version still throws errors at auto-imported composition API functions with the error message:

>Corresponding file is not included in tsconfig.json

Whats wrong here, what can I do to fix it?

I added a standardized ts.json config and setup the project as typical, it shouldn't have errors here.

答案1

得分: 1

作为一种解决方法,对我来说,使用Typescript v4而不是v5有效。这似乎是WebStorm的一个bug。

英文:

As a workaround, using Typescript v4 instead of v5 worked for me. It seems like it’s a bug of WebStorm.

答案2

得分: 0

问题

在使用 defineProps 时遇到了相同的问题,并出现了 "tsconfig.json 文件中未包含相应文件" 的消息。这是一个基于 Vite.js 的项目,使用标准的 TypeScript 配置。这个问题没有影响构建过程,只是一个恼人的警告,并且在 IDE 中缺少自动补全。Intellij Idea 2022.2

解决方法

可以通过在 tsconfig.json 中添加对 defineProps 函数定义的引用来解决此问题。对于 Vue 3.3,示例如下:

{
  //... tsconfig.json
  "files": ["node_modules/@vue/runtime-core/dist/runtime-core.d.ts"]
}
英文:

Issue

Had the same problem with defineProps and Corresponding file is not included in tsconfig.json message. A Vite.js based project with standard TypeScript config. The problem did not interfere the bulding process, just an annoying warning and lack of auto-completion in IDE. Intellij Idea 2022.2

Solution

The issue may be fixed by adding the reference to the definition of the defineProps function in the tsconfig.json. For Vue 3.3 the sample is below

{
  //... tsconfig.json
  &quot;files&quot;: [&quot;node_modules/@vue/runtime-core/dist/runtime-core.d.ts&quot;]
}

huangapple
  • 本文由 发表于 2023年5月26日 16:30:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339033.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定