Error: The specified 'supportedValuesOf' property is not present in the 'Intl' type

My current date-time library is dayJS and I am looking to display a comprehensive list of all available time zones.
I attempted to utilize the Intl object for this purpose:

Intl.supportedValuesOf("timeZone")

However, I encountered a typescript error:
TS2339: Property 'supportedValuesOf' does not exist on type 'typeof Intl'.

Although I can retrieve the values, I would like to avoid using the @ts-ignore notation

What is the recommended approach to add the updated types for the Intl object?

Answer №2

Encountering the same issue led me to delve deeper into the existing solutions.

If you need to utilize the method Intl.supportedValuesOf() on earlier versions of Typescript before 5.1, you can establish a file named Intl.d.ts (the name is flexible) and insert the following code:

declare namespace Intl {
  type Key = "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit";

  function supportedValuesOf(input: Key): string[];
}

Next, in the tsconfig.json file, include the relative path to the Intl.d.ts file we just generated within the "include" property, as shown below:

{
  "compilerOptions": {
    ...
  },
  "include": ["/custom/Intl.d.ts"]
}

A restart of your application might be necessary to observe the updates.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I encountered an issue with Typescript Jest where it was unable to find the mock or mockReturnedValue functions on the types I

Let's test out this interesting class: //RequestHandler.js import axios, {AxiosInstance} from 'axios'; import settings from './settings'; const axiosHandler: AxiosInstance = axios.create({ baseURL: 'http://localhost:8081&a ...

Encountering difficulties when compiling my Angular application

Currently, I am working with Angular 2. To include Bootstrap in my project, I utilized the node.js command prompt for installation. npm install ngx-bootstrap --save I made adjustments to the .csproj file in order to deploy my application on the server vi ...

Tips for sorting/merging/consolidating data in Angular

Take a look at this code snippet: rowData = [ [ '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2019-12-10 08:00:00', '2018-12-10 08:00:00' ...

Do null and undefined fall under other types as subcategories in Typescript?

As I was exploring some old code, I came across the following snippet: let isNew: boolean = null let myName: string = undefined This snippet seems to indicate that in typescript, a variable of type boolean can accept null and a variable of type string can ...

Troubleshooting a NextJs/TS problem with importing ESM modules

Click here for the Code Sandbox I'm currently in the process of transitioning some code to NextJS 11 / Webpack 5, including certain modules that now exclusively support ECMAScript Modules (esm). Prior to the upgrade, I could easily export all files ...

Vue 3 - Compelled to utilize any data type with computedRef

Recently, I've been diving into Vue/Typescript and encountered a puzzling error. The issue revolves around a class named UploadableFile: export class UploadableFile { file: File; dimensions: Ref; price: ComputedRef<number>; ... constr ...

Encountering the error "TypeError: null is not an object (evaluating '_ref.user')" with onAuthStateChanged in React Native using Firebase and useContext

I'm encountering an error in my useCachedResources.ts file and I'm uncertain of the cause. These three files are what I'm currently working with. I have a suspicion that the issue lies in the initial null value, but I am conditionally render ...

Show the key and value of a JSON object in a React component

When attempting to parse a JSON data file, I encountered an error message stating: "Element implicitly has an 'any' type because expression of type 'string' can't be used to the index type." The JSON data is sourced locally from a ...

Executing a NestJS script via the command line command

Looking to parse an XML file using the NestJS framework for a proof-of-concept, but feeling stuck on how to proceed. I've set up a scripts directory within /src, and placed my script.ts in there with an initial console.log. How do I execute commands ...

Tips for implementing absolute paths and baseUrl in TypeScript compiler

When I bundle a package using tsc, I am getting incorrect output. Here is the structure of my project directory: common └── index.ts types ├── action.ts ├── index.ts └── request.ts utils ├── event.ts ├── index.ts ├─ ...

Angular2: Once user is authenticated, navigate to specific routes

I've developed an admin panel with a router for page navigation. The layout of the admin panel includes a sidebar (Component), header (Component), and content (Component). Within the content, I have inserted <router-outlet></router-outlet> ...

The push() method encounters an error displaying the message: "Unable to append a new attribute."

Check out the code snippet below: const saveReserve = () => { if (polygons && creatingPolygon) { let last = creatingPolygon.coordinates[creatingPolygon.coordinates.length - 1][0][0]; console.log({last, polygons}) let newline = polygons. Co ...

Utilize mapGetter and mapMutations in Vuex with TypeScript without the need for class-style components syntax

After completing a project in Vue, I found myself getting a bit confused without static types. To address this, I decided to incorporate TypeScript into my project while still maintaining the traditional way of writing code, without classes and decorators. ...

Why bother specifying types when extending tsconfig?

Having an angular app that utilizes @types and custom typings, I am facing an issue where the app works when served but encounters errors during testing with ng test. It is puzzling to me why this discrepancy exists, and I am struggling to comprehend the r ...

Tips for constructing node.js projects using local versions of the dependencies?

Recently, I've been tackling a rather intricate node.js project (find it at https://github.com/edrlab/thorium-reader/) while trying to incorporate local versions of certain dependencies. Surprisingly, I can successfully build and execute the project ...

Is there a way to combine multiple array objects by comparing just one distinct element?

Is there a way to combine these two arrays into one? array1 = [ { image: 'image1', title: 'title1' }, { image: 'image2', title: 'title2' }, { image: 'image3', title: 'title3' }, ]; array2 = ...

What is the best way to incorporate data types into a React useReducer reducer function?

I originally had a useReducer function in pure react without TypeScript, but now I want to add types to it. Here is the useReducer reducer function in pure react without types: export const cartReducer = (state, action) => { switch (action.type) { ...

The comparison between importing TypeScript and ES2015 modules

I am currently facing an issue with TypeScript not recognizing the "default export" of react. Previously, in my JavaScript files, I used: import React from 'react'; import ReactDOM from 'react-dom'; However, in TypeScript, I found tha ...

Error thrown due to syntax issues in react.d.ts declaration file in TypeScript

Currently, I am attempting to integrate react with typescript in my project. However, typescript is generating syntax errors for the react.d.ts file sourced from Github: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/react The encountered ...

What is the technique for accessing the original function within a class using a proxy?

I attempted to monkey patch a function within my class using Proxy. Is there a way to access and execute the original function? class foo { x = 10; bar() { console.log({ x: this.x }); } } foo.prototype.bar = new Proxy(foo.prototype.bar, { ap ...