Skip to content

Commit 6aaeb52

Browse files
committed
Accept new baselines
1 parent f73308b commit 6aaeb52

File tree

4 files changed

+735
-0
lines changed

4 files changed

+735
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
tests/cases/compiler/reverseMappedPartiallyInferableTypes.ts(91,20): error TS2571: Object is of type 'unknown'.
2+
3+
4+
==== tests/cases/compiler/reverseMappedPartiallyInferableTypes.ts (1 errors) ====
5+
// Repro from #30505
6+
7+
export type Prop<T> = { (): T }
8+
export type PropType<T> = Prop<T>;
9+
export type PropDefaultValue<T> = T;
10+
11+
12+
export type PropValidatorFunction<T> = (value: T) => boolean;
13+
export type PropValidator<T> = PropOptions<T>;
14+
15+
16+
export type PropOptions<T> = {
17+
type: PropType<T>;
18+
19+
value?: PropDefaultValue<T>,
20+
required?: boolean;
21+
validator?: PropValidatorFunction<T>;
22+
}
23+
24+
export type RecordPropsDefinition<T> = {
25+
[K in keyof T]: PropValidator<T[K]>
26+
}
27+
export type PropsDefinition<T> = RecordPropsDefinition<T>;
28+
29+
30+
declare function extend<T>({ props }: { props: PropsDefinition<T> }): PropsDefinition<T>;
31+
32+
interface MyType {
33+
valid: boolean;
34+
}
35+
36+
const r = extend({
37+
props: {
38+
notResolved: {
39+
type: Object as PropType<MyType>,
40+
validator: x => {
41+
return x.valid;
42+
}
43+
},
44+
explicit: {
45+
type: Object as PropType<MyType>,
46+
validator: (x: MyType) => {
47+
return x.valid;
48+
}
49+
}
50+
}
51+
})
52+
53+
r.explicit
54+
r.notResolved
55+
r.explicit.required
56+
r.notResolved.required
57+
58+
// Modified repro from #30505
59+
60+
type Box<T> = {
61+
contents?: T;
62+
contains?(content: T): boolean;
63+
};
64+
65+
type Mapped<T> = {
66+
[K in keyof T]: Box<T[K]>;
67+
}
68+
69+
declare function id<T>(arg: Mapped<T>): Mapped<T>;
70+
71+
// All properties have inferable types
72+
73+
const obj1 = id({
74+
foo: {
75+
contents: ""
76+
}
77+
});
78+
79+
// Some properties have inferable types
80+
81+
const obj2 = id({
82+
foo: {
83+
contents: "",
84+
contains(k) {
85+
return k.length > 0;
86+
}
87+
}
88+
});
89+
90+
// No properties have inferable types
91+
92+
const obj3 = id({
93+
foo: {
94+
contains(k) {
95+
return k.length > 0;
96+
~
97+
!!! error TS2571: Object is of type 'unknown'.
98+
}
99+
}
100+
});
101+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//// [reverseMappedPartiallyInferableTypes.ts]
2+
// Repro from #30505
3+
4+
export type Prop<T> = { (): T }
5+
export type PropType<T> = Prop<T>;
6+
export type PropDefaultValue<T> = T;
7+
8+
9+
export type PropValidatorFunction<T> = (value: T) => boolean;
10+
export type PropValidator<T> = PropOptions<T>;
11+
12+
13+
export type PropOptions<T> = {
14+
type: PropType<T>;
15+
16+
value?: PropDefaultValue<T>,
17+
required?: boolean;
18+
validator?: PropValidatorFunction<T>;
19+
}
20+
21+
export type RecordPropsDefinition<T> = {
22+
[K in keyof T]: PropValidator<T[K]>
23+
}
24+
export type PropsDefinition<T> = RecordPropsDefinition<T>;
25+
26+
27+
declare function extend<T>({ props }: { props: PropsDefinition<T> }): PropsDefinition<T>;
28+
29+
interface MyType {
30+
valid: boolean;
31+
}
32+
33+
const r = extend({
34+
props: {
35+
notResolved: {
36+
type: Object as PropType<MyType>,
37+
validator: x => {
38+
return x.valid;
39+
}
40+
},
41+
explicit: {
42+
type: Object as PropType<MyType>,
43+
validator: (x: MyType) => {
44+
return x.valid;
45+
}
46+
}
47+
}
48+
})
49+
50+
r.explicit
51+
r.notResolved
52+
r.explicit.required
53+
r.notResolved.required
54+
55+
// Modified repro from #30505
56+
57+
type Box<T> = {
58+
contents?: T;
59+
contains?(content: T): boolean;
60+
};
61+
62+
type Mapped<T> = {
63+
[K in keyof T]: Box<T[K]>;
64+
}
65+
66+
declare function id<T>(arg: Mapped<T>): Mapped<T>;
67+
68+
// All properties have inferable types
69+
70+
const obj1 = id({
71+
foo: {
72+
contents: ""
73+
}
74+
});
75+
76+
// Some properties have inferable types
77+
78+
const obj2 = id({
79+
foo: {
80+
contents: "",
81+
contains(k) {
82+
return k.length > 0;
83+
}
84+
}
85+
});
86+
87+
// No properties have inferable types
88+
89+
const obj3 = id({
90+
foo: {
91+
contains(k) {
92+
return k.length > 0;
93+
}
94+
}
95+
});
96+
97+
98+
//// [reverseMappedPartiallyInferableTypes.js]
99+
"use strict";
100+
// Repro from #30505
101+
exports.__esModule = true;
102+
var r = extend({
103+
props: {
104+
notResolved: {
105+
type: Object,
106+
validator: function (x) {
107+
return x.valid;
108+
}
109+
},
110+
explicit: {
111+
type: Object,
112+
validator: function (x) {
113+
return x.valid;
114+
}
115+
}
116+
}
117+
});
118+
r.explicit;
119+
r.notResolved;
120+
r.explicit.required;
121+
r.notResolved.required;
122+
// All properties have inferable types
123+
var obj1 = id({
124+
foo: {
125+
contents: ""
126+
}
127+
});
128+
// Some properties have inferable types
129+
var obj2 = id({
130+
foo: {
131+
contents: "",
132+
contains: function (k) {
133+
return k.length > 0;
134+
}
135+
}
136+
});
137+
// No properties have inferable types
138+
var obj3 = id({
139+
foo: {
140+
contains: function (k) {
141+
return k.length > 0;
142+
}
143+
}
144+
});

0 commit comments

Comments
 (0)