Assume inputting a sentence contains one or two spaces and has the structure ${Verb}${one or two spaces}${Activity}, how could I extract the Verb and Activity in Typescript?
type Split = ' ' | ' '
type ExtractVerb<S extends string> =
S extends `${infer Verb}${Split}${infer Activity}`
? [Verb, Activity]
: never;
type Verbs = ExtractVerb<"play chess" | "write code" | "read hacker news">
I got the result type ["play", "chess"] | ["write", " code" | "code"] | ["read" | "read hacker", "hacker news" | "news"].
Expected: ["play", "chess"] | ["write", "code"] | ["read", "hacker news"].