Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreutils: add required TS intl libraries #16288

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/coreutils/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const UNITS: { name: Intl.RelativeTimeFormatUnit; milliseconds: number }[] = [
* The namespace for date functions.
*/
export namespace Time {
// Intl.RelativeTimeFormatStyle contains these, but it requires `ES2020.Intl`.
// We currently compile to an `ES2018` target.
export type HumanStyle = 'long' | 'short' | 'narrow';
export type HumanStyle = Intl.ResolvedRelativeTimeFormatOptions["style"];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could target Intl.RelativeTimeFormatStyle as originally proposed. The only downside to this is that there is a proposal to rename the RelativeTimeFormat option types to bring them in line with the Intl namespace convention (which would be Intl.RelativeTimeFormatOptionsStyle), so this type name may be removed or deprecated in a future TypeScript release.

This approach resolves the type to Intl.RelativeTimeFormatStyle indirectly, so that any such change would be automatically accounted for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it does not compile:

  ../coreutils/lib/time.d.ts(5,28): error TS2724: 'Intl' has no exported member named 'ResolvedRelativeTimeFormatOptions'. Did you mean 'ResolvedDateTimeFormatOptions'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was missing from the PR (mea culpa) was the default library set in tsconfigbase. This seems like an acceptable approach, given that Jupyter explicitly relies on features defined in those libraries.

Renegade334 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Convert a timestring to a human readable string (e.g. 'two minutes ago').
Expand Down
3 changes: 2 additions & 1 deletion packages/coreutils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"outDir": "lib",
"rootDir": "src",
"module": "commonjs",
"types": ["node"]
"types": ["node"],
"lib": ["DOM", "ES2018", "ES2020.Intl", "ES2021.Intl"]
},
"include": ["src/*"],
"references": []
Expand Down