打字稿配置

发布于 2025-01-25 12:58:47 字数 745 浏览 4 评论 0原文

我是TypeScript世界的新手,因此我有一些配置问题。问题在于,即使理论上应该这样做,某些方法也无法正常工作。当前我的打字稿配置看起来如下:

    {
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "noEmitOnError": true,
    "strictNullChecks": true,
    "lib": [
      "dom",
      "ES2015.Collection",
      "ES2015.Iterable",
      "ES2016.Array.include",
      "ES2017.Object",
      "ES5",
      "ES6",
    ],
  }
}

除了我尝试使用示例number.isinteger()方法或array.entries()方法以下事实外,一切似乎都很好:

属性'iSinteger'不存在于类型的“ numberConstructor”上。您需要更改目标库吗?尝试将“ LIB”编译器选项更改为“ ES2015”或更高版本。

.entries()也是如此。谁能帮忙?

I'm new to the world of typeScript, hence I'm having some configuration issues. The problem is that some methods are not working even though they theoretically should. Currently my typeScript config looks as follows:

    {
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "noEmitOnError": true,
    "strictNullChecks": true,
    "lib": [
      "dom",
      "ES2015.Collection",
      "ES2015.Iterable",
      "ES2016.Array.include",
      "ES2017.Object",
      "ES5",
      "ES6",
    ],
  }
}

Everything seems to be fine besides the fact that when I try to use for example Number.isInteger() method or Array.entries() method following error occurs:

Property 'isInteger' does not exist on type 'NumberConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

The same happens with .entries(). Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢欲 2025-02-01 12:58:47

以下是来自TypeScript游乐场。如果您关注链接并切换选项,则可以弄清楚您的需求。看起来您需要更多的ES2015,当目标是ES5时,它们显示为错误。

console.log(Number.isInteger(1))
const arr = [1, 2, 3]
console.log(arr.entries())

Output

"use strict";
console.log(Number.isInteger(1));
const arr = [1, 2, 3];
console.log(arr.entries());

Compiler Options

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

The following is from the Typescript playground. If you follow the link and toggle the options, you can figure out what you need. Looks like you need more of ES2015, they show as errors when target is ES5.

console.log(Number.isInteger(1))
const arr = [1, 2, 3]
console.log(arr.entries())

Output

"use strict";
console.log(Number.isInteger(1));
const arr = [1, 2, 3];
console.log(arr.entries());

Compiler Options

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文