cf.completefrontend

Predict the typesHard

What do these template literal types infer?

Name the type each ^? line points at, and list the errors TypeScript reports.

What does TypeScript report here?
type Split<S> = S extends `${infer Head}.${infer Rest}` ? [Head, Rest] : [S];type A = Split<"user.address.city">;//   ^? type Chars<S> = S extends `${infer First}${infer Rest}` ? [First, Rest] : never;type B = Chars<"abc">;//   ^?type C = Chars<"">;//   ^? type ToNumber<S> = S extends `${infer N extends number}` ? N : never;type D = ToNumber<"42">;//   ^?type E = ToNumber<"007">;//   ^? type UserPath = `/users/${string}`;const list: UserPath = "/users/";const post: UserPath = "/posts/42";

Work it out first: the compiler shows every error and type.

The answer

Work out every error TypeScript reports and every type it shows, line by line. Then check.

Checking your sign-in…