标签: tsconfig

TypeScript 3.7.2 - 当前未启用对实验性语法“optionalChaining”的支持

在我的项目中,我使用 TS 3.7.2,它应该支持可选链接。但是当我尝试这样使用它时:const state = urlParams.state?.toString()我收到错误:

当前未启用对实验性语法“optionalChaining”的支持

将 @babel/plugin-proposal-optional-chaining ( https://git.io/vb4Sk ) 添加到 Babel 配置的“插件”部分以启用转换。

我查看了发行说明,没有看到有关为该功能添加 tsconfig 选项的任何要求。

我想知道我已经在使用 TS 时是否需要 babel 插件和配置,我应该如何修复错误?

typescript tsconfig optional-chaining

19
推荐指数
2
解决办法
1万
查看次数

警告:找不到父tsconfig.json

我想修正警告:

警告:找不到父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)

intellij-idea webstorm typescript tsconfig

18
推荐指数
2
解决办法
9073
查看次数

在 tsconfig.json 中启用声明和声明映射的用例是什么?

如果我们启用允许我们在浏览器上调试的 sourcemap。同样寻找声明和声明映射的用例。

我已经在互联网上进行了搜索,但除了生成 .d.ts 文件之外,我的错误找不到实际的用例。

typescript tsconfig

17
推荐指数
2
解决办法
2872
查看次数

为什么 VSCode 不获取 tsconfig 中的路径别名?

我有一个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)

typescript tsconfig visual-studio-code vscode-jsconfig

17
推荐指数
1
解决办法
2万
查看次数

在tsconfig.json中排除模式

有没有办法在tsconfig文件的exclude属性中添加模式,还是只能支持目录?

我试图从编译中排除我的所有测试文件,所以我想知道我是否可以使用这样的东西:

SRC/**/*.spec.ts

好像它不起作用.

typescript tsconfig

16
推荐指数
2
解决办法
1万
查看次数

仅在node_modules中跳过库检查

有几个关于在错误输入中禁用错误​​的问题node_modules(例如,这个这个),但它们都涉及使用skipLibCheck编译器标志.

是否有其他解决此问题的方法(例如,使用includeexclude)?我有几个手写的.d.ts文件(更严格的类型比可在DefinitelyTyped),我想类型检查,所以类型检查对这些文件的批发禁止是没有吸引力.

node-modules typescript tsconfig

16
推荐指数
1
解决办法
845
查看次数

修复 TS2688:在 node_modules 中找不到类型定义文件

运行 tsc 时,我得到许多TS2688: Cannot find type definition file for 'someLibrary' 这些库来自node_modules. 我尝试在 tsconfig 中排除node_modulesskipLibCheck,但它们都不适合我。知道为什么会发生这种情况吗?

这是我的 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)

typescript tsc tsconfig

16
推荐指数
2
解决办法
4万
查看次数

类型“BehaviorSubject<false>”不可分配给类型“BehaviorSubject<boolean>”

我的一个组件中有这个:

\n
public booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);\n
Run Code Online (Sandbox Code Playgroud)\n

当我添加"strictFunctionTypes": truetsconfig.json文件时,出现以下错误:

\n
\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

\n

typescript tsconfig angular

16
推荐指数
2
解决办法
7412
查看次数

Typescript 编译器选项 - 尝试将“平面”输出输出到 outDir

我有一个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.tstest目录中删除,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"],但这没有帮助。 …

typescript tsconfig

15
推荐指数
1
解决办法
7779
查看次数

在 tsconfig.json 中找不到“body-parser”的类型定义文件

我在 [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)

typescript reactjs tsconfig body-parser

15
推荐指数
3
解决办法
2万
查看次数