admin管理员组

文章数量:1333389

I am using nodeJS v12.10.0 This supports Intl.ListFormat Using Typescript v3.6.3

However, when piling with typescript, I get Property 'ListFormat' does not exist on type 'typeof Intl' (ts2339) error.

I've tried googling and found this and other advice, but nothing has worked.

A consensus of what I've found seems to be to use a name.d.ts file and to somehow extend the Intl object there, but I haven't been able to.

I am still learning typescript, but am familiar with javascript.

I am using nodeJS v12.10.0 This supports Intl.ListFormat Using Typescript v3.6.3

However, when piling with typescript, I get Property 'ListFormat' does not exist on type 'typeof Intl' (ts2339) error.

I've tried googling and found this and other advice, but nothing has worked.

A consensus of what I've found seems to be to use a name.d.ts file and to somehow extend the Intl object there, but I haven't been able to.

I am still learning typescript, but am familiar with javascript.

Share Improve this question edited Sep 17, 2019 at 22:08 James Wilson asked Sep 16, 2019 at 21:21 James WilsonJames Wilson 94213 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I found that the accepted answer didn't work for me. I used the following:

declare namespace Intl {
  class ListFormat {
    constructor(locales?: string | string[], options?: Intl.ListFormatOptions);
    public format: (items: string[]) => string;
  }
}

Adding the following in a something.d.ts file seems to work.

declare namespace Intl {
  class ListFormat {
    public format: (items: [string?]) => string;
  }
}

I got the idea from my original googling, but then reading this helped me work it out.

Posting this in case it helps others.

本文标签: javascriptHow can I add types to use IntlListFormat in node v12Stack Overflow