typescript 命名空间“Intl”没有导出的成员“LocalesArgument”

hs1rzwqc  于 2023-05-19  发布在  TypeScript
关注(0)|答案(2)|浏览(189)

使用React和TypeScript,我试图输入一个函数,将参数传递给Date.toLocaleString,但当我尝试使用Intl.LocalesArgument时,我得到一个错误,说Namespace 'Intl' has no exported member 'LocalesArgument'。我的tsconfig.json在下面,我已经尝试将target更改为es2020并重新启动开发服务器,但无济于事。

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext",
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "useUnknownInCatchVariables": false
  },
  "include": [
    "src"
  ]
}
azpvetkf

azpvetkf1#

我使用的是TypeScript 4.6.3,升级到最新版本(撰写本文时为4.8.2)解决了这个问题。

fcipmucu

fcipmucu2#

如果您无法更新版本,可以通过转到tsconfig并将“ES2020.Intl”添加到“Lib”数组来解决:

"compilerOptions": {
  ...
  "lib": [<other libs>, "ES2020.Intl"]
  ...
}

相关问题