Skip to content

Commit 4476718

Browse files
committed
feat: add 0545-hard-printf
1 parent 6222a59 commit 4476718

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Equal, Expect } from "@type-challenges/utils";
2+
3+
type cases = [
4+
Expect<Equal<Format<"abc">, string>>,
5+
Expect<Equal<Format<"a%sbc">, (s1: string) => string>>,
6+
Expect<Equal<Format<"a%dbc">, (d1: number) => string>>,
7+
Expect<Equal<Format<"a%dbc%s">, (d1: number) => (s1: string) => string>>
8+
];

0 commit comments

Comments
 (0)