Skip to content

Commit

Permalink
Join: Faster handing of readonly empty tuple (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa authored Nov 20, 2023
1 parent fe03e0a commit 855fb64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/join.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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], ''>}`
Expand Down
5 changes: 5 additions & 0 deletions test-d/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ','> = '';
Expand Down

0 comments on commit 855fb64

Please sign in to comment.