TypeScript 当配置设置已经被缓存时,typeAcquisition.exclude将忽略更改,

yk9xbfzb  于 4个月前  发布在  TypeScript
关注(0)|答案(3)|浏览(44)

TypeScript Version: 4.0.5
Search Terms: typeAcquisition exclude
Code

Use the following jsconfig.json file:

{
    "compilerOptions": {
        "checkJs": true,
        "strict": true,
        "resolveJsonModule": true,
    },
    "include":[
        "./**/*",
    ],
    "typeAcquisition": {
        "exclude": [
            "copy-webpack-plugin"
        ]
    }
}

Expected behavior:

When identifying that the source of a type-related issue exists in the automatically acquired type declarations, it is natural to add that package to the typeAcquisition.exclude array in the [j/t]sconfig.json file.
Once this is done, the TypeScript language service should not use automatically acquired type declarations for the specified package (the copy-webpack-plugin package in the example above).
In other words, a user should be able to make the configuration adjustment, restart the TypeScript/JavaScript Language Service and find that any packages newly added to the "typeAcquisition.excluded" array should no longer use automatically acquired packages.

Actual behavior:

The TypeScript language service continues to use automatically acquired type declarations for the newly excluded package.
To be clear, in the example above, setting typeAcquisition.enable = falsedoes disable the type acquisition for copy-webpack-plugin .
Manually "uninstalling" the type declarations (using, for example, npm uninstall --save-dev @types/copy-webpack-plugin ) allowed the typeAcquisition.exclude setting to work as expected. In my case, the cache in question was located at ~/.cache/typescript/4.0 .

Playground Link:
N/A. The Playground does not have an option to configure the typeAcquisition setting.
Related Issues:

Couldn't find any.

wwodge7n

wwodge7n1#

请明确,这是在VSCode v1.51.1中使用Remote Containers扩展v0.148.1(devcontainer运行在node:10)运行的。

s71maibg

s71maibg2#

我们能解决这个问题吗?在我电脑上,我正在分别使用 react 17 和 18 开发两个项目。react 18 项目运行正常,但在 react 17 项目中,我遇到了这样的错误信息:

'ThemeProvider' cannot be used as a JSX component.
  Its instance type 'Component<ThemeProviderProps<any, any>, any, any>' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("/Users/.../Library/Caches/typescript/4.6/node_modules/@types/react/index").ReactNode'.

我认为在 "typeAcquisition": { "exclude": ["react"] } 中添加 jsconfig.json 并本地安装 @types/react@^17 应该解决这个警告,但现在它不起作用。

yvt65v4c

yvt65v4c3#

我们能解决这个问题吗?我在电脑上分别使用react 17和18开发两个项目。react 18项目运行正常,但在react 17项目中,我遇到了这样的错误信息:

'ThemeProvider' cannot be used as a JSX component.
  Its instance type 'Component<ThemeProviderProps<any, any>, any, any>' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("/Users/.../Library/Caches/typescript/4.6/node_modules/@types/react/index").ReactNode'.

我认为在"typeAcquisition": { "exclude": ["react"] }中添加jsconfig.json并在本地安装@types/react@^17应该解决这个警告,但现在它不起作用。
对我来说也是同样的问题。

相关问题