Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TS2339: Property 'DisplayNames' does not exist on type 'typeof Intl'

How can i fix that type error? TS2339: Property 'DisplayNames' does not exist on type 'typeof Intl'.

my function:

export const getLanguageName = (locale: string | null) => {
  const localeName = new Intl.DisplayNames([locale], { type: 'language' });
  return localeName.of(locale);
};
like image 900
Cor4zon Avatar asked Oct 15 '25 21:10

Cor4zon


1 Answers

If you arrived here looking for an Angular solution, I think it's safe to just use target: "es2020" and update your library declarations in your tsconfig.base.ts (at the root level)

{
    "compilerOptions": {
            ...
            "target": "es2020",
            "lib": ["dom", "es2020"]
    }
}

That should give you access to the new Intl API types definitions removing the errors from your editor and also any possible compilation errors. A few years ago we could only use es2015 due to some issues with async/await and zone.js but this was addressed in 2021.

like image 116
guzmanoj Avatar answered Oct 17 '25 12:10

guzmanoj