microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.08k stars 12.49k forks source link

typeAcquisition.exclude configuration settings changes are ignored when already cached #41501

Open ericdrobinson opened 4 years ago

ericdrobinson commented 4 years ago

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 = false does 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.

ericdrobinson commented 4 years ago

To be clear, this is running in VSCode v1.51.1 using the Remote Containers extension v0.148.1 (devcontainer running on node:10).

chochihim commented 2 years ago

Can we have this fix? In my computer I am working on two projects using react 17 and 18 respectively. The react 18 project works fine but in the react 17 project, I encounter error message like this

'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'.

I think adding "typeAcquisition": { "exclude": ["react"] } in jsconfig.json and installing @types/react@^17 locally should resolve this warning but it is not working right now

AJ0363075 commented 2 years ago

Can we have this fix? In my computer I am working on two projects using react 17 and 18 respectively. The react 18 project works fine but in the react 17 project, I encounter error message like this

'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'.

I think adding "typeAcquisition": { "exclude": ["react"] } in jsconfig.json and installing @types/react@^17 locally should resolve this warning but it is not working right now

exactly same issue for me