We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6222a59 commit 4476718Copy full SHA for 4476718
type-challenges/0545-hard-printf/template.ts
@@ -0,0 +1,9 @@
1
+// 参考 https://github.com/type-challenges/type-challenges/issues/2112
2
+type CharToType = {
3
+ s: string;
4
+ d: number;
5
+};
6
+
7
+type Format<T extends string> = T extends `${infer F}%${infer Char}${infer L}`
8
+ ? (arg: Char extends keyof CharToType ? CharToType[Char] : never) => Format<L>
9
+ : string;
type-challenges/0545-hard-printf/test-cases.ts
@@ -0,0 +1,8 @@
+import type { Equal, Expect } from "@type-challenges/utils";
+type cases = [
+ Expect<Equal<Format<"abc">, string>>,
+ Expect<Equal<Format<"a%sbc">, (s1: string) => string>>,
+ Expect<Equal<Format<"a%dbc">, (d1: number) => string>>,
+ Expect<Equal<Format<"a%dbc%s">, (d1: number) => (s1: string) => string>>
+];
0 commit comments