Skip to content

Commit 853b881

Browse files
authored
Split: Fix behavior with template strings ending with interpolated types (#1204)
1 parent 3130e77 commit 853b881

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

source/split.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ type SplitHelper<
7878
? S extends `${infer Head}${Delimiter}${infer Tail}`
7979
? SplitHelper<Tail, Delimiter, Options, [...Accumulator, Head]>
8080
: Delimiter extends ''
81-
? Accumulator
81+
? S extends ''
82+
? Accumulator
83+
: [...Accumulator, S]
8284
: [...Accumulator, S]
8385
// Otherwise, return `string[]`
8486
: string[]

test-d/split.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ expectType<['a', 'b', 'c'] | ['a,b,c'] | ['x', 'y', 'z'] | ['x:y:z']>({} as Spli
4040
// which, when split by `.`, would result in `['a', 'b', 'c', 'd']`, which wouldn't conform to the output type of `['a', 'b', string]`.
4141
expectType<['a', 'b', string]>({} as Split<`a.b.${string}`, '.', {strictLiteralChecks: false}>);
4242

43+
// Ensure the last dynamic "string" is not dropped when split by `''`.
44+
// https://github.com/sindresorhus/type-fest/issues/1203
45+
expectType<['a', 'b', string]>({} as Split<`ab${string}`, '', {strictLiteralChecks: false}>);
46+
4347
// -- strictLiteralChecks: true --
4448
expectType<string[]>({} as Split<string, ''>);
4549
expectType<string[]>({} as Split<Uppercase<string>, '-'>);

0 commit comments

Comments
 (0)