typescriptvisual-studio-code

TypeScript problems remembered in VS Code after renaming to .js


I have a .js file which was originally a .ts file, but had problems when running with Vite and Node thus changed to .js.
However, now that it's a .js file it still shows TypeScript errors (ts(7006) and ts(7017)).

I have tried deleting the file and restarting VS Code, but when I restore the file from git the errors are still shown.

I can prevent the error from showing using comment hints, e.g. // @ts-ignore, but I'd prefer not to.

If I create a new dummy.js and paste the contents of the ts file then no errors are shown for dummy.js.

What is causing this problem and how can I prevent the renamed file from generating errors?

vscode screenshot

tsconfig.json

{
    "extends": "./.svelte-kit/tsconfig.json",
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true,
        "moduleResolution": "bundler",
        "types": ["vitest/globals"]
    }
    // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
    // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
    //
    // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
    // from the referenced tsconfig.json - TypeScript does not merge them in
}

--- Edit ---
Thanks Hugo, restarting the typescript language server didn't change anything.
I pasted the tsconfig above.
Setting "checkJs": false suppresses the error, but I wasn't expecting ts to checkJs so I've learned why and I'm happy to leave it as true.

Dummy.js also produces errors when referenced from a ts source file.


Solution

  • Have you tried the following options?

    In any case, what does your tsconfig file look like?