From 855fb642f243b677a10e4b410e7dc06fdbeebf20 Mon Sep 17 00:00:00 2001 From: Haozheng Li Date: Mon, 20 Nov 2023 19:28:13 +0800 Subject: [PATCH] `Join`: Faster handing of readonly empty tuple (#765) --- source/join.d.ts | 2 +- test-d/join.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/join.d.ts b/source/join.d.ts index 3418362c..442f85d3 100644 --- a/source/join.d.ts +++ b/source/join.d.ts @@ -51,7 +51,7 @@ const path: Join<['hello' | undefined, 'world' | null], '.'> = ['hello', 'world' export type Join< Items extends readonly JoinableItem[], Delimiter extends string, -> = Items extends [] +> = Items extends readonly [] ? '' : Items extends readonly [JoinableItem?] ? `${NullishCoalesce}` diff --git a/test-d/join.ts b/test-d/join.ts index 2edf51da..9a7a2015 100644 --- a/test-d/join.ts +++ b/test-d/join.ts @@ -48,6 +48,11 @@ const tuple = ['foo', 'bar', 'baz'] as const; const joinedTuple: Join = 'foo,bar,baz'; expectType<'foo,bar,baz'>(joinedTuple); +// Typeof of const empty tuple. +const emptyTuple = [] as const; +const joinedEmptyTuple: Join = ''; +expectType<''>(joinedEmptyTuple); + // Typeof of string[]. const stringArray = ['foo', 'bar', 'baz']; const joinedStringArray: Join = '';