We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3554199 commit 91ecf26Copy full SHA for 91ecf26
1 file changed
projects/type-operations/template-literal-type-shenanigans/03-split-on/solution.ts
@@ -3,5 +3,11 @@ export type SplitOn<
3
On extends string,
4
Results extends string[] = [],
5
> = Text extends `${infer Prefix}${On}${infer Suffix}`
6
- ? SplitOn<Suffix, On, [Prefix, ...Results]>
7
- : [Text, ...Results];
+ ? SplitOn<Suffix, On, [...Results, Prefix]>
+ : [...Results, Text];
8
+
9
+type Wat1 = SplitOn<"baby", "a">;
10
+// ^?
11
12
+type Wat2 = SplitOn<"hello my baby", " ">;
13
0 commit comments