Skip to content

Commit 91ecf26

Browse files
fix: correct reversed types in 03-split-on
1 parent 3554199 commit 91ecf26

File tree

1 file changed

+8
-2
lines changed
  • projects/type-operations/template-literal-type-shenanigans/03-split-on

1 file changed

+8
-2
lines changed

projects/type-operations/template-literal-type-shenanigans/03-split-on/solution.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ export type SplitOn<
33
On extends string,
44
Results extends string[] = [],
55
> = Text extends `${infer Prefix}${On}${infer Suffix}`
6-
? SplitOn<Suffix, On, [Prefix, ...Results]>
7-
: [Text, ...Results];
6+
? SplitOn<Suffix, On, [...Results, Prefix]>
7+
: [...Results, Text];
8+
9+
type Wat1 = SplitOn<"baby", "a">;
10+
// ^?
11+
12+
type Wat2 = SplitOn<"hello my baby", " ">;
13+
// ^?

0 commit comments

Comments
 (0)