admin管理员组文章数量:1356760
I have a project with js files, where I enabled type checking across multiple modules (highlighting wrong parameters etc of function imported from different module) in VS Code by creating this jsconfig.json:
{
"pilerOptions": {
"checkJs": true
}
}
Now, I read that typescript 4.5 supports mjs files
So I installed typescript 4.5 beta, node 17, and modified jsconfig.json to this:
{
"pilerOptions": {
"module": "node12",
"moduleResolution": "node",
"checkJs": true
}
}
but it still doesn't work for mjs files, and I also get this error in jsconfig.json:
Argument for '--module' option must be: 'none', 'monjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'
Any idea how to enable type checking for mjs files across multiple modules?
I have a project with js files, where I enabled type checking across multiple modules (highlighting wrong parameters etc of function imported from different module) in VS Code by creating this jsconfig.json:
{
"pilerOptions": {
"checkJs": true
}
}
Now, I read that typescript 4.5 supports mjs files https://github./microsoft/TypeScript/issues/27957
So I installed typescript 4.5 beta, node 17, and modified jsconfig.json to this:
{
"pilerOptions": {
"module": "node12",
"moduleResolution": "node",
"checkJs": true
}
}
but it still doesn't work for mjs files, and I also get this error in jsconfig.json:
Argument for '--module' option must be: 'none', 'monjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'
Any idea how to enable type checking for mjs files across multiple modules?
Share Improve this question asked Oct 20, 2021 at 11:22 sede10gsede10g 1272 silver badges8 bronze badges 2- Any luck on this? Maybe you need to use node v16 (latest LTS), not node v17? – Devin Rhode Commented Feb 28, 2022 at 4:30
- Official docs page: typescriptlang/docs/handbook/esm-node.html – Devin Rhode Commented Feb 28, 2022 at 16:19
2 Answers
Reset to default 5Consider using these tsconfig.json options:
{
"pilerOptions": {
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext"
},
"include": ["**/*.mjs"]
}
=======
Here's ALL the changes I did along with adding .mjs support. I don't think they are all strictly necessary, but I want to share for pleteness:
Modified my package.json type-check
script:
"type-check": "tsc --pretty --noEmit && tsc --pretty --noEmit --project tsconfig.mjs.json",
Here's my tsconfig.mjs.json file:
{
"extends": "./tsconfig.json",
"pilerOptions": {
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext"
},
"include": ["**/*.mjs"]
}
Run:
yarn add @typescript-eslint/eslint-plugin @typescript-eslint/parser --dev
yarn remove typescript
yarn add typescript # use latest
Likely, you will get an error that you need to use typescript nightly build to actually type-check mjs files. Run:
yarn remove typescript
yarn add typescript@next --dev
I know that you were asking for a solution to typecheck all .mjs
files automatically, but maybe the following might be interesting for others:
As long as you only have a few .mjs
files that you want to typecheck with TypeScript, you can just add //@ts-check
in the first line of each .mjs
file.
Check the Typescript docs for more details.
本文标签: javascriptHow to enable type checking of mjs files in VS CodeStack Overflow
版权声明:本文标题:javascript - How to enable type checking of mjs files in VS Code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744059834a2583926.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论