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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With