Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'RelativeTimeFormat' does not exist on type 'typeof Intl'

Tags:

typescript

There are no errors while writing the code, but this occurs during compilation:

src/index.ts:2:24 - error TS2339: Property 'RelativeTimeFormat' does not exist on type 'typeof Intl'.

2   const rtf = new Intl.RelativeTimeFormat("en", { style: "long" });
                         ~~~~~~~~~~~~~~~~~~


Found 1 error.

Although this problem should have been solved after this PR.

My tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "outDir": "lib",
    "lib": [
      "DOM",
      "ESNext"
    ],
    "strict": true,
    "declaration": true,
    "removeComments": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "importHelpers": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "isolatedModules": true
  },
  "include": [
    "src"
  ]
}

TypeScript version: 4.0.3

like image 929
Wondermarin Avatar asked Nov 07 '22 04:11

Wondermarin


1 Answers

According to the PR you linked, it was only published with TypeScript v4.1.2. Also, it is part of the es2020.intl TypeScript lib definition.

You first need to install a more up to date version of typescript: `npm install -D typescript@^4.1.2

Then you must update your tsconfig with something like:

"compilerOptions": {
  ...
  "lib": [
    "DOM",
    "ES2020",
    "ESNext"
    ],
  ...
}

Another solution would be to use a polyfill instead. This will ensure that your React application works in older browser not supporting the ES2020 standard. See here https://formatjs.io/docs/polyfills/intl-relativetimeformat/

like image 145
Hugodby Avatar answered Nov 14 '22 23:11

Hugodby