Skip to content

Commit 0e0975d

Browse files
authored
Add extra tests for inference with any co-inference with a different contra-inference (#57917)
1 parent d660bab commit 0e0975d

4 files changed

+279
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
coAndContraVariantInferences6.ts(34,42): error TS2322: Type '"C"' is not assignable to type '"A" | "B"'.
2+
3+
4+
==== coAndContraVariantInferences6.ts (1 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/57911
6+
7+
interface ExactProps {
8+
value: "A" | "B";
9+
}
10+
interface FunctionComponent<P = {}> {
11+
(props: P): ReactElement<any> | null;
12+
}
13+
declare class Component<P> {
14+
constructor(props: P);
15+
}
16+
interface ComponentClass<P = {}> {
17+
new (props: P): Component<P>;
18+
}
19+
20+
interface ReactElement<
21+
T extends string | JSXElementConstructor<any> =
22+
| string
23+
| JSXElementConstructor<any>,
24+
> {
25+
type: T;
26+
}
27+
28+
type JSXElementConstructor<P> =
29+
| ((props: P) => ReactElement<any> | null)
30+
| (new (props: P) => Component<any>);
31+
32+
declare function createElementIsolated<P extends {}>(
33+
type: FunctionComponent<P> | ComponentClass<P> | string,
34+
props?: P | null,
35+
): void;
36+
37+
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
38+
createElementIsolated(WrapperIsolated, { value: "C" });
39+
~~~~~
40+
!!! error TS2322: Type '"C"' is not assignable to type '"A" | "B"'.
41+
42+
declare const props: any[];
43+
declare const stat: any;
44+
[].push.apply(props, stat.properties);
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//// [tests/cases/compiler/coAndContraVariantInferences6.ts] ////
2+
3+
=== coAndContraVariantInferences6.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/57911
5+
6+
interface ExactProps {
7+
>ExactProps : Symbol(ExactProps, Decl(coAndContraVariantInferences6.ts, 0, 0))
8+
9+
value: "A" | "B";
10+
>value : Symbol(ExactProps.value, Decl(coAndContraVariantInferences6.ts, 2, 22))
11+
}
12+
interface FunctionComponent<P = {}> {
13+
>FunctionComponent : Symbol(FunctionComponent, Decl(coAndContraVariantInferences6.ts, 4, 1))
14+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 5, 28))
15+
16+
(props: P): ReactElement<any> | null;
17+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 6, 3))
18+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 5, 28))
19+
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
20+
}
21+
declare class Component<P> {
22+
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
23+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 8, 24))
24+
25+
constructor(props: P);
26+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 9, 14))
27+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 8, 24))
28+
}
29+
interface ComponentClass<P = {}> {
30+
>ComponentClass : Symbol(ComponentClass, Decl(coAndContraVariantInferences6.ts, 10, 1))
31+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
32+
33+
new (props: P): Component<P>;
34+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 12, 7))
35+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
36+
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
37+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
38+
}
39+
40+
interface ReactElement<
41+
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
42+
43+
T extends string | JSXElementConstructor<any> =
44+
>T : Symbol(T, Decl(coAndContraVariantInferences6.ts, 15, 23))
45+
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
46+
47+
| string
48+
| JSXElementConstructor<any>,
49+
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
50+
51+
> {
52+
type: T;
53+
>type : Symbol(ReactElement.type, Decl(coAndContraVariantInferences6.ts, 19, 3))
54+
>T : Symbol(T, Decl(coAndContraVariantInferences6.ts, 15, 23))
55+
}
56+
57+
type JSXElementConstructor<P> =
58+
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
59+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
60+
61+
| ((props: P) => ReactElement<any> | null)
62+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 24, 6))
63+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
64+
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
65+
66+
| (new (props: P) => Component<any>);
67+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 25, 10))
68+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
69+
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
70+
71+
declare function createElementIsolated<P extends {}>(
72+
>createElementIsolated : Symbol(createElementIsolated, Decl(coAndContraVariantInferences6.ts, 25, 39))
73+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
74+
75+
type: FunctionComponent<P> | ComponentClass<P> | string,
76+
>type : Symbol(type, Decl(coAndContraVariantInferences6.ts, 27, 53))
77+
>FunctionComponent : Symbol(FunctionComponent, Decl(coAndContraVariantInferences6.ts, 4, 1))
78+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
79+
>ComponentClass : Symbol(ComponentClass, Decl(coAndContraVariantInferences6.ts, 10, 1))
80+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
81+
82+
props?: P | null,
83+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 28, 58))
84+
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
85+
86+
): void;
87+
88+
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
89+
>WrapperIsolated : Symbol(WrapperIsolated, Decl(coAndContraVariantInferences6.ts, 32, 11))
90+
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
91+
>ExactProps : Symbol(ExactProps, Decl(coAndContraVariantInferences6.ts, 0, 0))
92+
93+
createElementIsolated(WrapperIsolated, { value: "C" });
94+
>createElementIsolated : Symbol(createElementIsolated, Decl(coAndContraVariantInferences6.ts, 25, 39))
95+
>WrapperIsolated : Symbol(WrapperIsolated, Decl(coAndContraVariantInferences6.ts, 32, 11))
96+
>value : Symbol(value, Decl(coAndContraVariantInferences6.ts, 33, 40))
97+
98+
declare const props: any[];
99+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 35, 13))
100+
101+
declare const stat: any;
102+
>stat : Symbol(stat, Decl(coAndContraVariantInferences6.ts, 36, 13))
103+
104+
[].push.apply(props, stat.properties);
105+
>[].push.apply : Symbol(CallableFunction.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
106+
>[].push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
107+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
108+
>apply : Symbol(CallableFunction.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
109+
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 35, 13))
110+
>stat : Symbol(stat, Decl(coAndContraVariantInferences6.ts, 36, 13))
111+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//// [tests/cases/compiler/coAndContraVariantInferences6.ts] ////
2+
3+
=== coAndContraVariantInferences6.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/57911
5+
6+
interface ExactProps {
7+
value: "A" | "B";
8+
>value : "A" | "B"
9+
}
10+
interface FunctionComponent<P = {}> {
11+
(props: P): ReactElement<any> | null;
12+
>props : P
13+
}
14+
declare class Component<P> {
15+
>Component : Component<P>
16+
17+
constructor(props: P);
18+
>props : P
19+
}
20+
interface ComponentClass<P = {}> {
21+
new (props: P): Component<P>;
22+
>props : P
23+
}
24+
25+
interface ReactElement<
26+
T extends string | JSXElementConstructor<any> =
27+
| string
28+
| JSXElementConstructor<any>,
29+
> {
30+
type: T;
31+
>type : T
32+
}
33+
34+
type JSXElementConstructor<P> =
35+
>JSXElementConstructor : JSXElementConstructor<P>
36+
37+
| ((props: P) => ReactElement<any> | null)
38+
>props : P
39+
40+
| (new (props: P) => Component<any>);
41+
>props : P
42+
43+
declare function createElementIsolated<P extends {}>(
44+
>createElementIsolated : <P extends {}>(type: FunctionComponent<P> | ComponentClass<P> | string, props?: P | null) => void
45+
46+
type: FunctionComponent<P> | ComponentClass<P> | string,
47+
>type : string | FunctionComponent<P> | ComponentClass<P>
48+
49+
props?: P | null,
50+
>props : P | null | undefined
51+
52+
): void;
53+
54+
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
55+
>WrapperIsolated : JSXElementConstructor<ExactProps>
56+
57+
createElementIsolated(WrapperIsolated, { value: "C" });
58+
>createElementIsolated(WrapperIsolated, { value: "C" }) : void
59+
>createElementIsolated : <P extends {}>(type: string | FunctionComponent<P> | ComponentClass<P>, props?: P | null | undefined) => void
60+
>WrapperIsolated : JSXElementConstructor<ExactProps>
61+
>{ value: "C" } : { value: "C"; }
62+
>value : "C"
63+
>"C" : "C"
64+
65+
declare const props: any[];
66+
>props : any[]
67+
68+
declare const stat: any;
69+
>stat : any
70+
71+
[].push.apply(props, stat.properties);
72+
>[].push.apply(props, stat.properties) : number
73+
>[].push.apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T_1, A extends any[], R_1>(this: (this: T_1, ...args: A) => R_1, thisArg: T_1, args: A): R_1; }
74+
>[].push : (...items: never[]) => number
75+
>[] : never[]
76+
>push : (...items: never[]) => number
77+
>apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T_1, A extends any[], R_1>(this: (this: T_1, ...args: A) => R_1, thisArg: T_1, args: A): R_1; }
78+
>props : any[]
79+
>stat.properties : any
80+
>stat : any
81+
>properties : any
82+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/57911
5+
6+
interface ExactProps {
7+
value: "A" | "B";
8+
}
9+
interface FunctionComponent<P = {}> {
10+
(props: P): ReactElement<any> | null;
11+
}
12+
declare class Component<P> {
13+
constructor(props: P);
14+
}
15+
interface ComponentClass<P = {}> {
16+
new (props: P): Component<P>;
17+
}
18+
19+
interface ReactElement<
20+
T extends string | JSXElementConstructor<any> =
21+
| string
22+
| JSXElementConstructor<any>,
23+
> {
24+
type: T;
25+
}
26+
27+
type JSXElementConstructor<P> =
28+
| ((props: P) => ReactElement<any> | null)
29+
| (new (props: P) => Component<any>);
30+
31+
declare function createElementIsolated<P extends {}>(
32+
type: FunctionComponent<P> | ComponentClass<P> | string,
33+
props?: P | null,
34+
): void;
35+
36+
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
37+
createElementIsolated(WrapperIsolated, { value: "C" });
38+
39+
declare const props: any[];
40+
declare const stat: any;
41+
[].push.apply(props, stat.properties);

0 commit comments

Comments
 (0)