Skip to content

Commit b261e29

Browse files
committed
test generic type
1 parent 3815aa7 commit b261e29

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

tests/baselines/reference/contextualTypeInObectProperty.errors.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ tests/cases/compiler/contextualTypeInObectProperty.ts(24,11): error TS7006: Para
4646
[getC()]: function() {
4747
this.c();
4848
}
49-
};
49+
};
50+
51+
52+
declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
53+
f({ data: 0 }, {
54+
[(() => 'data' as const)()](value, key) {
55+
56+
},
57+
});

tests/baselines/reference/contextualTypeInObectProperty.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ const thisType = {
3535
[getC()]: function() {
3636
this.c();
3737
}
38-
};
38+
};
39+
40+
41+
declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
42+
f({ data: 0 }, {
43+
[(() => 'data' as const)()](value, key) {
44+
45+
},
46+
});
3947

4048
//// [contextualTypeInObectProperty.js]
4149
"use strict";
42-
var _a, _b, _c, _d, _e;
50+
var _a, _b, _c, _d, _e, _f;
4351
exports.__esModule = true;
4452
exports.func = exports.unionType = exports.obj = void 0;
4553
var getC = function () { return "c"; };
@@ -63,3 +71,7 @@ var thisType = (_e = {},
6371
this.c();
6472
},
6573
_e);
74+
f({ data: 0 }, (_f = {},
75+
_f[(function () { return 'data'; })()] = function (value, key) {
76+
},
77+
_f));

tests/baselines/reference/contextualTypeInObectProperty.symbols

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,30 @@ const thisType = {
103103
>c : Symbol([getC()], Decl(contextualTypeInObectProperty.ts, 32, 18))
104104
}
105105
};
106+
107+
108+
declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
109+
>f : Symbol(f, Decl(contextualTypeInObectProperty.ts, 36, 2))
110+
>T : Symbol(T, Decl(contextualTypeInObectProperty.ts, 39, 19))
111+
>data : Symbol(data, Decl(contextualTypeInObectProperty.ts, 39, 37))
112+
>T : Symbol(T, Decl(contextualTypeInObectProperty.ts, 39, 19))
113+
>handlers : Symbol(handlers, Decl(contextualTypeInObectProperty.ts, 39, 45))
114+
>P : Symbol(P, Decl(contextualTypeInObectProperty.ts, 39, 59))
115+
>T : Symbol(T, Decl(contextualTypeInObectProperty.ts, 39, 19))
116+
>value : Symbol(value, Decl(contextualTypeInObectProperty.ts, 39, 75))
117+
>T : Symbol(T, Decl(contextualTypeInObectProperty.ts, 39, 19))
118+
>P : Symbol(P, Decl(contextualTypeInObectProperty.ts, 39, 59))
119+
>prop : Symbol(prop, Decl(contextualTypeInObectProperty.ts, 39, 87))
120+
>P : Symbol(P, Decl(contextualTypeInObectProperty.ts, 39, 59))
121+
122+
f({ data: 0 }, {
123+
>f : Symbol(f, Decl(contextualTypeInObectProperty.ts, 36, 2))
124+
>data : Symbol(data, Decl(contextualTypeInObectProperty.ts, 40, 3))
125+
126+
[(() => 'data' as const)()](value, key) {
127+
>[(() => 'data' as const)()] : Symbol([(() => 'data' as const)()], Decl(contextualTypeInObectProperty.ts, 40, 16))
128+
>value : Symbol(value, Decl(contextualTypeInObectProperty.ts, 41, 30))
129+
>key : Symbol(key, Decl(contextualTypeInObectProperty.ts, 41, 36))
130+
131+
},
132+
});

tests/baselines/reference/contextualTypeInObectProperty.types

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,32 @@ const thisType = {
123123
>c : () => void
124124
}
125125
};
126+
127+
128+
declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
129+
>f : <T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }) => void
130+
>data : T
131+
>handlers : { [P in keyof T]: (value: T[P], prop: P) => void; }
132+
>value : T[P]
133+
>prop : P
134+
135+
f({ data: 0 }, {
136+
>f({ data: 0 }, { [(() => 'data' as const)()](value, key) { },}) : void
137+
>f : <T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }) => void
138+
>{ data: 0 } : { data: number; }
139+
>data : number
140+
>0 : 0
141+
>{ [(() => 'data' as const)()](value, key) { },} : { data(value: number, key: "data"): void; }
142+
143+
[(() => 'data' as const)()](value, key) {
144+
>[(() => 'data' as const)()] : (value: number, key: "data") => void
145+
>(() => 'data' as const)() : "data"
146+
>(() => 'data' as const) : () => "data"
147+
>() => 'data' as const : () => "data"
148+
>'data' as const : "data"
149+
>'data' : "data"
150+
>value : number
151+
>key : "data"
152+
153+
},
154+
});

tests/cases/compiler/contextualTypeInObectProperty.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ const thisType = {
3737
[getC()]: function() {
3838
this.c();
3939
}
40-
};
40+
};
41+
42+
43+
declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void;
44+
f({ data: 0 }, {
45+
[(() => 'data' as const)()](value, key) {
46+
47+
},
48+
});

0 commit comments

Comments
 (0)