Join: Faster handing of readonly empty tuple (#765)

This commit is contained in:
Haozheng Li 2023-11-20 19:28:13 +08:00 committed by GitHub
parent fe03e0a87a
commit 855fb642f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

2
source/join.d.ts vendored
View File

@ -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<Items[0], ''>}`

View File

@ -48,6 +48,11 @@ const tuple = ['foo', 'bar', 'baz'] as const;
const joinedTuple: Join<typeof tuple, ','> = 'foo,bar,baz';
expectType<'foo,bar,baz'>(joinedTuple);
// Typeof of const empty tuple.
const emptyTuple = [] as const;
const joinedEmptyTuple: Join<typeof emptyTuple, ','> = '';
expectType<''>(joinedEmptyTuple);
// Typeof of string[].
const stringArray = ['foo', 'bar', 'baz'];
const joinedStringArray: Join<typeof stringArray, ','> = '';