Skip to content

Commit e344996

Browse files
committed
Added type tests to 17.5
1 parent 37241ea commit e344996

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/04-generics-advanced/17.5-inference-inside-generic-functions.problem.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Equal, Expect } from "../helpers/type-utils";
2+
13
type Person = {
24
name: string;
35
age: number;
@@ -14,3 +16,13 @@ export function remapPerson<Key extends keyof Person>(
1416

1517
return value;
1618
}
19+
20+
const date = remapPerson("birthdate", new Date());
21+
const num = remapPerson("age", 42);
22+
const name = remapPerson("name", "John Doe");
23+
24+
type tests = [
25+
Expect<Equal<typeof date, Date>>,
26+
Expect<Equal<typeof num, number>>,
27+
Expect<Equal<typeof name, string>>,
28+
];

src/04-generics-advanced/17.5-inference-inside-generic-functions.solution.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Equal, Expect } from "../helpers/type-utils";
2+
13
type Person = {
24
name: string;
35
age: number;
@@ -14,3 +16,13 @@ export function remapPerson<Key extends keyof Person>(
1416

1517
return value;
1618
}
19+
20+
const date = remapPerson("birthdate", new Date());
21+
const num = remapPerson("age", 42);
22+
const name = remapPerson("name", "John Doe");
23+
24+
type tests = [
25+
Expect<Equal<typeof date, Date>>,
26+
Expect<Equal<typeof num, number>>,
27+
Expect<Equal<typeof name, string>>,
28+
];

0 commit comments

Comments
 (0)