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

Add Intl.ListFormat to es2021 lib #46907

Closed
5 tasks done
vhfmag opened this issue Nov 23, 2021 · 11 comments Β· Fixed by #47254
Closed
5 tasks done

Add Intl.ListFormat to es2021 lib #46907

vhfmag opened this issue Nov 23, 2021 · 11 comments Β· Fixed by #47254
Labels
Committed The team has roadmapped this issue Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@vhfmag
Copy link

vhfmag commented Nov 23, 2021

Suggestion

πŸ” Search Terms

  • Intl.ListFormat
  • Intl
  • ListFormat

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Add Intl.ListFormat to es2021 lib types (as per Finished Proposals).

Bringing this API to Typescript has been directly suggested before, but didn't follow the issue templates (#46866), and was also mentioned before (#45646 (comment), #29129 (comment)), but, as I couldn't find any specific active issue where the feature suggestion is being considered, I'm opening this issue.

πŸ“ƒ Motivating Example

Code that uses the Intl.ListFormat API should not fail type checking:

new Intl.ListFormat('bg', {type: 'conjunction'}).format(['a','b','c'])
new Intl.ListFormat('bg', {type: 'disjunction'}).formatToParts(['a','b','c'])

πŸ’» Use Cases

new Intl.ListFormat('bg', {type: 'conjunction'}).format(['a','b','c'])
new Intl.ListFormat('bg', {type: 'disjunction'}).formatToParts(['a','b','c'])
@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript labels Nov 29, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 29, 2021
@saschanaz
Copy link
Contributor

It's ES2021 per the Finished Proposals list.

@vhfmag vhfmag changed the title Add Intl.ListFormat to es2020 lib Add Intl.ListFormat to es2021 lib Dec 12, 2021
@vhfmag
Copy link
Author

vhfmag commented Dec 12, 2021

Thanks for pointing that out, I've updated the issue accordingly.

@chasm
Copy link

chasm commented Dec 25, 2021

Is there a workaround for this?

@vhfmag
Copy link
Author

vhfmag commented Dec 25, 2021

Personally, I used something like:

declare namespace Intl {
    type ListType = "conjunction" | "disjunction";

    interface ListFormatOptions {
        localeMatcher?: "lookup" | "best fit";
        type?: ListType;
        style?: "long" | "short" | "narrow";
    }

    interface ListFormatPart {
        type: "element" | "literal";
        value: string;
    }

    class ListFormat {
        constructor(locales?: string | string[], options?: ListFormatOptions);
        format(values: any[]): string;
        formatToParts(values: any[]): ListFormatPart[];
        supportedLocalesOf(
            locales: string | string[],
            options?: ListFormatOptions,
        ): string[];
    }
}

@chasm
Copy link

chasm commented Dec 25, 2021

Thanks for the help. That works great for making the linting errors go away, but (I'm using Deno) I still get [ERROR]: Property 'ListFormat' does not exist on type 'typeof Intl'. when I try to bundle it or run tests. And yet it works fine in the Deno REPL, so I know that it does exist.... I guess I don't understand Deno/TS enough to see what's going on.

@andreubotella
Copy link
Contributor

andreubotella commented Dec 25, 2021

The Deno REPL uses swc to transpile TypeScript without doing any type-checking, so that difference doesn't mean Deno or TypeScript comes with typings for Intl.ListFormat.

@chasm
Copy link

chasm commented Dec 26, 2021

Yes. I understood that. The types are missing, but the REPL cares not. But the actual code must be there or it wouldn't work at all, no? The VSCode linter picks up the above namespace declaration and the red squiggles go away, but clearly the bundler and test in Deno do not, as they fail the type check.

@vhfmag
Copy link
Author

vhfmag commented Dec 26, 2021

@chasm I haven't much experience with it, but I found this in Deno's docs:

Another option is to use a configuration file that is configured to include the type definitions, by supplying a "types" value to the "compilerOptions". For example:

{
  "compilerOptions": {
    "types": [
      "./types.d.ts",
      "https://deno.land/x/[email protected]/types.d.ts",
      "/Users/me/pkg/types.d.ts"
    ]
  }
}

Maybe refering to the .d.ts file would make the bundler aware of it?

@chasm
Copy link

chasm commented Dec 26, 2021

Excellent. I will check that out. Thanks.

@AndreMantas
Copy link

is this live? i cant find ListFormat after installing https://www.npmjs.com/package/@types/intl

@saschanaz
Copy link
Contributor

This is live, and that package is outdated and should not be required in any situation. Make sure your target is es2021 or higher, and if that still doesn't work, please open a new issue rather than commenting on an old issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants