我尝试使用typescript 3.7Optional Chaining、Nullish Coalescing 等功能。但是在转换时webpack给我一个错误。
app: Module parse failed: Unexpected token (50:40)
app: File was processed with these loaders:
app: * ../../../node_modules/ts-loader/index.js
app: You may need an additional loader to handle the result of these loaders.
app: | export const Layout = (props) => {
app: | const regionsResults = useQuery(regionsQuery, { fetchPolicy: 'cache-first' });
app: > const regions = regionsResults.data?.regions ?? [];
app: | const userItem = useQuery(usersProfileQuery, { fetchPolicy: 'cache-first' });
app: | const …Run Code Online (Sandbox Code Playgroud) 每次我在 Visual Studio Code 中打开一个新项目时,它都会默认使用自己的 TypeScript 版本,而不是工作区的版本。有没有办法默认使用工作区版本,这样我就不必每次都更改它?
\n例如,
\n\n我尝试查看设置,似乎只能提示我\xe2\x80\x94none 每次都默认为我想要的行为。
\n如何强制 Visual Studio Code 始终对所有项目使用工作区的 TypeScript 版本?
\n如果我故意在我的代码中打错字,我会得到一个错误。这是正确的代码:
declare const State: TwineState;
Run Code Online (Sandbox Code Playgroud)
如果我删除最后一个字符,然后在命令行上键入 tsc,则会出现以下错误:
tsc/prod.spec.ts:7:22 - error TS2304: Cannot find name 'TwineStat'.
7 declare const State: TwineStat;
Run Code Online (Sandbox Code Playgroud)
但是 Visual Studio Code 似乎没有意识到有任何错误。
我如何让我的编辑器向我显示 tsc 命令识别的相同错误?我对所有这些技术都很陌生,所以我不知道哪些信息有助于排除故障,但这是我的配置文件:
包.json:
{
...
"version": "1.0.0",
"main": ".webpack/main",
"scripts": {
"compile-typescript": "tsc && cp tscbuild/prod.js story/",
"lint": "eslint tsc/** --fix",
"test": "npm run lint && ts-node node_modules/jasmine/bin/jasmine && npm run compile-typescript ..."
},
"keywords": [],
...
"devDependencies": {
"@types/jasmine": "^3.5.9",
"@types/node": "^13.9.1",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"eslint": "^6.8.0",
"eslint-plugin-testcafe": "^0.2.1",
"jasmine": "^3.5.0",
"testcafe": …Run Code Online (Sandbox Code Playgroud) 在编辑该项目时,是否有一种方法可以强制Visual Studio Code使用本地安装在JS项目中的TypeScript(而不是与VSCode捆绑在一起的版本或全局安装的版本)进行类型检查?