在我的项目中,我使用 TS 3.7.2,它应该支持可选链接。但是当我尝试这样使用它时:const state = urlParams.state?.toString()
我收到错误:
当前未启用对实验性语法“optionalChaining”的支持
将 @babel/plugin-proposal-optional-chaining ( https://git.io/vb4Sk ) 添加到 Babel 配置的“插件”部分以启用转换。
我查看了发行说明,没有看到有关为该功能添加 tsconfig 选项的任何要求。
我想知道我已经在使用 TS 时是否需要 babel 插件和配置,我应该如何修复错误?
我想修正警告:
警告:找不到父tsconfig.json
在TypeScript Errors
选项卡中IntelliJ IDEA 2016.3
.我的TypeScript代码存在于src
目录中,我的TypeScript输出lib
将按预期进行,src
而不会添加文件夹lib
.
我lib
在其他项目中使用该文件夹,它似乎按预期工作.所以这似乎不是一个大问题,但我偶尔会遇到TSLint的问题,它有时似乎没有拿起.tsx
文件是JSX和lint错误,似乎偶尔将其视为普通.ts
文件.最终它似乎弄明白了.我想知道这是否与我的TSLint设置配置使用有关tsconfig.json
.
我之前已经.js
将文件转换成.ts
文件src
夹中的文件旁边的文件,但是因为我tsconfig.json
最近修改了文件.
文件如下:
tsconfig.json
src/index.ts
lib/index.js
lib/index.d.ts
Run Code Online (Sandbox Code Playgroud)
我已经升级到TypeScript 2.1.4,但是看到了2.0.10.
我的tsconfig.json
档案:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"jsx": "react",
"allowJs": false,
"isolatedModules": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"noImplicitAny": false,
"noImplicitUseStrict": true,
"noEmitHelpers": false,
"removeComments": true,
"noLib": false,
"sourceMap": true,
"inlineSources": true, …
Run Code Online (Sandbox Code Playgroud) 如果我们启用允许我们在浏览器上调试的 sourcemap。同样寻找声明和声明映射的用例。
我已经在互联网上进行了搜索,但除了生成 .d.ts 文件之外,我的错误找不到实际的用例。
我有一个jsconfig.json
,我用一个替换了tsconfig.json
。替换后,VSCode 不会获取路径别名并报告导入错误:
例子:
Cannot find module '@Components/Title' or its corresponding type declarations.ts(2307)
Run Code Online (Sandbox Code Playgroud)
jsconfig.json
// https://code.visualstudio.com/docs/languages/jsconfig
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@Components/*": ["./src/components/*"],
"@Modules/*": ["./src/modules/*"],
"@Styles/*": ["./src/styles/*"],
"@Content/*": ["./src/content/*"],
"@Apps/*": ["./src/apps/*"]
}
},
//Add any build/compiled folders here to stop vscode searching those
"exclude": ["node_modules", "build"]
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
// https://code.visualstudio.com/docs/languages/jsconfig
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@Components/*": ["./src/components/*"],
"@Modules/*": ["./src/modules/*"],
"@Styles/*": ["./src/styles/*"],
"@Content/*": ["./src/content/*"],
"@Apps/*": ["./src/apps/*"]
},
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": …
Run Code Online (Sandbox Code Playgroud) 有没有办法在tsconfig文件的exclude属性中添加模式,还是只能支持目录?
我试图从编译中排除我的所有测试文件,所以我想知道我是否可以使用这样的东西:
SRC/**/*.spec.ts
好像它不起作用.
运行 tsc 时,我得到许多TS2688: Cannot find type definition file for 'someLibrary'
这些库来自node_modules
. 我尝试在 tsconfig 中排除node_modules
和skipLibCheck
,但它们都不适合我。知道为什么会发生这种情况吗?
这是我的 tsconfig.json
{
"ts-node": {
"files": true,
"emit": true,
"compilerHost": true
},
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "es2016",
"sourceMap": true,
"typeRoots" : ["./node_modules","./node_modules/@types"],
"jsx": "react",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud) 我的一个组件中有这个:
\npublic booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);\n
Run Code Online (Sandbox Code Playgroud)\n当我添加"strictFunctionTypes": true
到tsconfig.json
文件时,出现以下错误:
\xc3\x97 Compiling TypeScript sources through NGC\nERROR: path/to/my/component.component.ts:28:10 - error TS2322: Type \'BehaviorSubject<false>\' is not assignable to type \'BehaviorSubject<boolean>\'.\n Types of property \'observers\' are incompatible.\n Type \'Observer<false>[]\' is not assignable to type \'Observer<boolean>[]\'.\n Type \'Observer<false>\' is not assignable to type \'Observer<boolean>\'.\n Type \'boolean\' is not assignable to type \'false\'.\n\n28 public booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);\n
Run Code Online (Sandbox Code Playgroud)\n有谁知道原因以及如何通过将标志设置为不抛出strictFunctionTypes
错误true
?
我有一个src
包含源代码和单元测试的目录,以及一个test
包含单独速度测试的目录。
当我使用 构建项目时tsc
,我得到如下目录结构:
dist/
src/
index.js
...
test/
speed-test.js
Run Code Online (Sandbox Code Playgroud)
然而,我更喜欢将“平面”输出发送到我的dist
目录,如下所示:
dist/
index.js
...
speed-test.js
...
Run Code Online (Sandbox Code Playgroud)
如果我speed-test.ts
从test
目录中删除,tsc
则不会将src
目录添加到dist
. 仅当需要(或者至少当tsc
决定需要时)来区分编译代码的源时,才会添加额外的目录结构。
我确信这有时对于避免文件名冲突非常有用,但在这种情况下这对我来说并不重要,而且我不想得到这个额外的“帮助”。
这是我的tsconfig.json
:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "./dist",
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试添加"rootDirs"
的选项["src", "test"]
,但这没有帮助。 …
我在 [1,1] 处的 tsconfig.json 文件中收到此错误六次:
Cannot find type definition file for 'body-parser'.
The file is in the program because:
Entry point for implicit type library 'body-parser'
Run Code Online (Sandbox Code Playgroud)
我真的不确定为什么会收到此错误,更不用说六次了。任何帮助将不胜感激。
这是我的 tsconfig:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
// "incremental": true, /* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo …
Run Code Online (Sandbox Code Playgroud) tsconfig ×10
typescript ×10
angular ×1
body-parser ×1
node-modules ×1
reactjs ×1
tsc ×1
webstorm ×1