From 76c7b9abf9876dde631d3b20c322a5b08a4a006d Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Mon, 17 Jan 2022 06:50:10 +0100 Subject: fix(tsc): Add typings for `Intl.ListFormat` (#13301) V8 has supported `Intl.ListFormat` since version 7.2, but TypeScript doesn't have typings for it yet. This PR manually adds those typings, copying them from microsoft/TypeScript#47254. --- cli/tests/unit/esnext_test.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/esnext_test.ts b/cli/tests/unit/esnext_test.ts index cc5e89e80..c6b3c07c2 100644 --- a/cli/tests/unit/esnext_test.ts +++ b/cli/tests/unit/esnext_test.ts @@ -23,3 +23,35 @@ Deno.test(function errorCause() { const e = new Error("test", { cause: "something" }); assertEquals(e.cause, "something"); }); + +Deno.test(function intlListFormat() { + const formatter = new Intl.ListFormat("en", { + style: "long", + type: "conjunction", + }); + assertEquals( + formatter.format(["red", "green", "blue"]), + "red, green, and blue", + ); + + const formatter2 = new Intl.ListFormat("en", { + style: "short", + type: "disjunction", + }); + assertEquals(formatter2.formatToParts(["Rust", "golang"]), [ + { type: "element", value: "Rust" }, + { type: "literal", value: " or " }, + { type: "element", value: "golang" }, + ]); + + // Works with iterables as well + assertEquals( + formatter.format(new Set(["red", "green", "blue"])), + "red, green, and blue", + ); + assertEquals(formatter2.formatToParts(new Set(["Rust", "golang"])), [ + { type: "element", value: "Rust" }, + { type: "literal", value: " or " }, + { type: "element", value: "golang" }, + ]); +}); -- cgit v1.2.3