hrtyy.dev

Typescript Memo

Memo for type techniques of Typescript.

Multiple inference in template literal type

1type MultipleInference<S extends string> = S extends `${infer X}${infer Y}` ? {x: X, y: Y} : never
2type Result = MultipleInference<"abcde">
3
4// OK
5// type Result = {
6// x: "a";
7// y: "bcde";
8// }
9
10// NG
11// type Result = {
12// x: "ab";
13// y: "cde";
14// }

Good Type Challenges

  • ReplaceAll https://github.com/type-challenges/type-challenges/blob/master/questions/119-medium-replaceall/README.md

  • IsNever https://github.com/type-challenges/type-challenges/blob/master/questions/1042-medium-isnever/README.md

  • IsUnion https://github.com/type-challenges/type-challenges/blob/master/questions/1097-medium-isunion/README.md

  • PickByType https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md

If you have any questions, please send an email tohoritayuya@gmail.com.