fullcalendar / temporal-polyfill

A lightweight polyfill for Temporal, successor to the JavaScript Date object
MIT License
361 stars 14 forks source link

TypeScript error: 'Intl' has no exported member 'DateTimeFormatPart' #8

Closed h-h-h-h closed 9 months ago

h-h-h-h commented 2 years ago

I'm just getting started with TypeScript and try to migrate a test project in VS Code to it.

I import this polyfill globally only in the entry point file with:

import 'temporal-polyfill/global'

Then, in other files, Temporal is unavailable. So, I tried this tsconfig.json:

{
  "include": [
    "./node_modules/temporal-polyfill/dist/global.d.ts"
  ]
}

Temporal is still unavailable and, for global.d.ts, this error is shown:

[line 9]     formatToParts(dateArg?: DateTimeFormatArg): Intl.DateTimeFormatPart[];
                                                              ^^^^^^^^^^^^^^^^^^
+------------------
| type Intl.DateTimeFormatPart = /*unresolved*/ any
| Namespace 'Intl' has no exported member 'DateTimeFormatPart'. ts(2694)
+--------------------

Also: Surely, it's not recommended to link to a file in node_modules. How is it done properly?


When I use this definition file in tsconfig.json instead, it works.

h-h-h-h commented 2 years ago

There's something strange going on, because, right after posting, the file from my last sentence stopped working with IteratorResult complained about.

I forgot to run npm install typescript --save-dev (oops). Still:

arshaw commented 9 months ago

Hi @h-h-h-h , this is happening because you have an old lib in your tsconfig. You can try adding lib: ['ES2020'] or add the Intl lib only like this.

It might actually be fixed in the most recent version (0.2.0) even without edits to lib because the typescript definitions access it in a possibly-safer way (globalThis.Intl.DateTimeFormatPart which might fallback to undefined). Would you mind giving 0.2.0 a spin?

h-h-h-h commented 9 months ago

Thank you, but I'm currently not working in the ecosystem anymore.