#`allowJs: true` makes VSCode type-check my `.mjs` file?

1 messages · Page 1 of 1 (latest)

golden agate
#

I've got a tsconfig.json with:

"allowJs": true

Because some parts of my project need to import js while we migrate to ts.

But it's causing type check errors in VSCode in my eslint.config.mjs file. ... why? I don't have checkJs enabled. The error I get is:

The inferred type of 'default' cannot be named without a reference to '.pnpm/[email protected][email protected]/node_modules/eslint'. This is likely not portable. A type annotation is necessary.

Well, this is a JavaScript file. I can't add a type annotation!?

cobalt bane
#

Do you see the same thing when you run tsc in the console? (If not, have you tried "Restart TS server" in VSCode?")

golden agate
#

No, I don't. Let me try another restart.

#

No change. I can see that if I disable "allowJs", the errors go away in my .mjs file immediately. (no reload needed).

#

(but, of course, I expect that'll break other parts of the project, so isn't the solution for this.)

echo tiger
#

setup include or exclude in tsconfig

#

otherwise it tries to type-check every file

golden agate
#

because of "allowJs"?

#

I was hoping I could // @ts-nocheck in the file, but that didn't work.

echo tiger
golden agate
#

I don't think my .mjs file is relying on any types...

cobalt bane
#

Technically a This is likely not portable. A type annotation is necessary. error is downstream of declaration: true - TS is trying to produce a d.ts file

golden agate
#

aaaah, you are correct.

cobalt bane
#

It may still try to do that even if checkJs is false - I think TS would still emit declaration files as best it can for 'included but not typechecked' files.

golden agate
#

I tried adding a /** @type { unknown } */ hoping to just let it declare the type as unknown, but that wasn't working either.

cobalt bane
#

But yeah, if you do include: ["src"] or whatever that should make the issue go away.