Skip to content

Commit 758884c

Browse files
authored
Add a test for a property of reverse mapped type having a primitive type (microsoft#55807)
1 parent 274821e commit 758884c

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/reverseMappedTypePrimitiveConstraintProperty.ts] ////
2+
3+
=== reverseMappedTypePrimitiveConstraintProperty.ts ===
4+
declare function test<
5+
>test : Symbol(test, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 0))
6+
7+
T extends { prop: string; nested: { nestedProp: string } },
8+
>T : Symbol(T, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 22))
9+
>prop : Symbol(prop, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 1, 13))
10+
>nested : Symbol(nested, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 1, 27))
11+
>nestedProp : Symbol(nestedProp, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 1, 37))
12+
13+
>(obj: { [K in keyof T]: T[K] }): T;
14+
>obj : Symbol(obj, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 2, 2))
15+
>K : Symbol(K, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 2, 10))
16+
>T : Symbol(T, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 22))
17+
>T : Symbol(T, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 22))
18+
>K : Symbol(K, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 2, 10))
19+
>T : Symbol(T, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 22))
20+
21+
const result = test({
22+
>result : Symbol(result, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 4, 5))
23+
>test : Symbol(test, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 0, 0))
24+
25+
prop: "foo", // this one should not widen to string
26+
>prop : Symbol(prop, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 4, 21))
27+
28+
nested: {
29+
>nested : Symbol(nested, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 5, 14))
30+
31+
nestedProp: "bar",
32+
>nestedProp : Symbol(nestedProp, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 6, 11))
33+
34+
},
35+
extra: "baz",
36+
>extra : Symbol(extra, Decl(reverseMappedTypePrimitiveConstraintProperty.ts, 8, 4))
37+
38+
});
39+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/reverseMappedTypePrimitiveConstraintProperty.ts] ////
2+
3+
=== reverseMappedTypePrimitiveConstraintProperty.ts ===
4+
declare function test<
5+
>test : <T extends { prop: string; nested: { nestedProp: string;}; }>(obj: { [K in keyof T]: T[K]; }) => T
6+
7+
T extends { prop: string; nested: { nestedProp: string } },
8+
>prop : string
9+
>nested : { nestedProp: string; }
10+
>nestedProp : string
11+
12+
>(obj: { [K in keyof T]: T[K] }): T;
13+
>obj : { [K in keyof T]: T[K]; }
14+
15+
const result = test({
16+
>result : { prop: "foo"; nested: { nestedProp: string; }; extra: string; }
17+
>test({ prop: "foo", // this one should not widen to string nested: { nestedProp: "bar", }, extra: "baz",}) : { prop: "foo"; nested: { nestedProp: string; }; extra: string; }
18+
>test : <T extends { prop: string; nested: { nestedProp: string; }; }>(obj: { [K in keyof T]: T[K]; }) => T
19+
>{ prop: "foo", // this one should not widen to string nested: { nestedProp: "bar", }, extra: "baz",} : { prop: "foo"; nested: { nestedProp: string; }; extra: string; }
20+
21+
prop: "foo", // this one should not widen to string
22+
>prop : "foo"
23+
>"foo" : "foo"
24+
25+
nested: {
26+
>nested : { nestedProp: string; }
27+
>{ nestedProp: "bar", } : { nestedProp: string; }
28+
29+
nestedProp: "bar",
30+
>nestedProp : string
31+
>"bar" : "bar"
32+
33+
},
34+
extra: "baz",
35+
>extra : string
36+
>"baz" : "baz"
37+
38+
});
39+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
declare function test<
5+
T extends { prop: string; nested: { nestedProp: string } },
6+
>(obj: { [K in keyof T]: T[K] }): T;
7+
8+
const result = test({
9+
prop: "foo", // this one should not widen to string
10+
nested: {
11+
nestedProp: "bar",
12+
},
13+
extra: "baz",
14+
});

0 commit comments

Comments
 (0)