TypeScript 如果在VSCode中将outDir设置为null,则会发出警告,

8mmmxcuj  于 9个月前  发布在  TypeScript
关注(0)|答案(3)|浏览(147)

TypeScript版本: 3.7.2
搜索词:

取消设置扩展tsconfig中的outDir
outDir null
outDir Type

代码

  1. {
  2. "extends": "./tsconfig",
  3. "compilerOptions": {
  4. //...
  5. "outDir": null,
  6. }
  7. }

预期行为:

在VSCode中没有警告。

实际行为:

  1. {
  2. "resource": "/home/jogo/dev/boomsaas/tsconfig.single.json",
  3. "owner": "_generated_diagnostic_collection_name_#0",
  4. "severity": 4,
  5. "message": "Incorrect type. Expected \"string\".",
  6. "startLineNumber": 6,
  7. "startColumn": 13,
  8. "endLineNumber": 6,
  9. "endColumn": 17
  10. }

我想在我的扩展配置中取消设置outDir配置,以便将转译后的文件放在源文件旁边。添加一个字符串""会使它们出现在根文件夹中。Null似乎可以正常工作。

daupos2t

daupos2t1#

我们需要修复这个问题。我认为在这里设置 null 不是有意为之的,但可能现在不止你一个人依赖这种行为,所以我们也应该添加一些明确的测试。

yyhrrdl8

yyhrrdl82#

我们还需要在commandLineParser中修复它。

zazmityj

zazmityj3#

在您的示例中,似乎您遗漏了 "rootDir" 选项,因为没有 "rootDir","outDir": "" 可以正常工作。

  1. "outDir": ""
  1. 35642
  2. - a
  3. - index.ts
  4. - tsconfig.json
  5. - b
  6. - index.ts
  7. - tsconfig.json
  8. - tsconfig.base.json
  1. // tsconfig.base.json
  2. {
  3. "compilerOptions": {
  4. "target": "es5",
  5. "module": "commonjs",
  6. "outDir": "dist"
  7. }
  8. }
  1. // index.ts
  2. const a = null;
  1. // a/tsconfig.json
  2. {
  3. "extends": "../tsconfig.base"
  4. }
  1. tsc -p ./a/tsconfig.json
  1. cat dist/index.js
  2. "use strict";
  3. var a = null;
  1. // index.ts
  2. const b = null;
  1. // b/tsconfig.json
  2. {
  3. "extends": "../tsconfig.base",
  4. "outDir": ""
  5. }
  1. tsc -p ./b/tsconfig.json

将结果放入 b 文件夹,而不是 dist

  1. cat b/index.js
  2. "use strict";
  3. var b = null;

@sheetalkamat 您是想把 outDir 的 "type" 从 "string" 改为 "string" | null 吗?
cc @RyanCavanaugh

展开查看全部

相关问题