mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
Add extra tests for inference with any co-inference with a different contra-inference (#57917)
This commit is contained in:
parent
d660bab254
commit
0e0975d1cf
@ -0,0 +1,45 @@
|
||||
coAndContraVariantInferences6.ts(34,42): error TS2322: Type '"C"' is not assignable to type '"A" | "B"'.
|
||||
|
||||
|
||||
==== coAndContraVariantInferences6.ts (1 errors) ====
|
||||
// https://github.com/microsoft/TypeScript/issues/57911
|
||||
|
||||
interface ExactProps {
|
||||
value: "A" | "B";
|
||||
}
|
||||
interface FunctionComponent<P = {}> {
|
||||
(props: P): ReactElement<any> | null;
|
||||
}
|
||||
declare class Component<P> {
|
||||
constructor(props: P);
|
||||
}
|
||||
interface ComponentClass<P = {}> {
|
||||
new (props: P): Component<P>;
|
||||
}
|
||||
|
||||
interface ReactElement<
|
||||
T extends string | JSXElementConstructor<any> =
|
||||
| string
|
||||
| JSXElementConstructor<any>,
|
||||
> {
|
||||
type: T;
|
||||
}
|
||||
|
||||
type JSXElementConstructor<P> =
|
||||
| ((props: P) => ReactElement<any> | null)
|
||||
| (new (props: P) => Component<any>);
|
||||
|
||||
declare function createElementIsolated<P extends {}>(
|
||||
type: FunctionComponent<P> | ComponentClass<P> | string,
|
||||
props?: P | null,
|
||||
): void;
|
||||
|
||||
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
|
||||
createElementIsolated(WrapperIsolated, { value: "C" });
|
||||
~~~~~
|
||||
!!! error TS2322: Type '"C"' is not assignable to type '"A" | "B"'.
|
||||
|
||||
declare const props: any[];
|
||||
declare const stat: any;
|
||||
[].push.apply(props, stat.properties);
|
||||
|
||||
111
tests/baselines/reference/coAndContraVariantInferences6.symbols
Normal file
111
tests/baselines/reference/coAndContraVariantInferences6.symbols
Normal file
@ -0,0 +1,111 @@
|
||||
//// [tests/cases/compiler/coAndContraVariantInferences6.ts] ////
|
||||
|
||||
=== coAndContraVariantInferences6.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/57911
|
||||
|
||||
interface ExactProps {
|
||||
>ExactProps : Symbol(ExactProps, Decl(coAndContraVariantInferences6.ts, 0, 0))
|
||||
|
||||
value: "A" | "B";
|
||||
>value : Symbol(ExactProps.value, Decl(coAndContraVariantInferences6.ts, 2, 22))
|
||||
}
|
||||
interface FunctionComponent<P = {}> {
|
||||
>FunctionComponent : Symbol(FunctionComponent, Decl(coAndContraVariantInferences6.ts, 4, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 5, 28))
|
||||
|
||||
(props: P): ReactElement<any> | null;
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 6, 3))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 5, 28))
|
||||
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
|
||||
}
|
||||
declare class Component<P> {
|
||||
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 8, 24))
|
||||
|
||||
constructor(props: P);
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 9, 14))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 8, 24))
|
||||
}
|
||||
interface ComponentClass<P = {}> {
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(coAndContraVariantInferences6.ts, 10, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
|
||||
|
||||
new (props: P): Component<P>;
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 12, 7))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
|
||||
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25))
|
||||
}
|
||||
|
||||
interface ReactElement<
|
||||
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
|
||||
|
||||
T extends string | JSXElementConstructor<any> =
|
||||
>T : Symbol(T, Decl(coAndContraVariantInferences6.ts, 15, 23))
|
||||
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
|
||||
|
||||
| string
|
||||
| JSXElementConstructor<any>,
|
||||
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
|
||||
|
||||
> {
|
||||
type: T;
|
||||
>type : Symbol(ReactElement.type, Decl(coAndContraVariantInferences6.ts, 19, 3))
|
||||
>T : Symbol(T, Decl(coAndContraVariantInferences6.ts, 15, 23))
|
||||
}
|
||||
|
||||
type JSXElementConstructor<P> =
|
||||
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
|
||||
|
||||
| ((props: P) => ReactElement<any> | null)
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 24, 6))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
|
||||
>ReactElement : Symbol(ReactElement, Decl(coAndContraVariantInferences6.ts, 13, 1))
|
||||
|
||||
| (new (props: P) => Component<any>);
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 25, 10))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27))
|
||||
>Component : Symbol(Component, Decl(coAndContraVariantInferences6.ts, 7, 1))
|
||||
|
||||
declare function createElementIsolated<P extends {}>(
|
||||
>createElementIsolated : Symbol(createElementIsolated, Decl(coAndContraVariantInferences6.ts, 25, 39))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
|
||||
|
||||
type: FunctionComponent<P> | ComponentClass<P> | string,
|
||||
>type : Symbol(type, Decl(coAndContraVariantInferences6.ts, 27, 53))
|
||||
>FunctionComponent : Symbol(FunctionComponent, Decl(coAndContraVariantInferences6.ts, 4, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
|
||||
>ComponentClass : Symbol(ComponentClass, Decl(coAndContraVariantInferences6.ts, 10, 1))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
|
||||
|
||||
props?: P | null,
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 28, 58))
|
||||
>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39))
|
||||
|
||||
): void;
|
||||
|
||||
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
|
||||
>WrapperIsolated : Symbol(WrapperIsolated, Decl(coAndContraVariantInferences6.ts, 32, 11))
|
||||
>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1))
|
||||
>ExactProps : Symbol(ExactProps, Decl(coAndContraVariantInferences6.ts, 0, 0))
|
||||
|
||||
createElementIsolated(WrapperIsolated, { value: "C" });
|
||||
>createElementIsolated : Symbol(createElementIsolated, Decl(coAndContraVariantInferences6.ts, 25, 39))
|
||||
>WrapperIsolated : Symbol(WrapperIsolated, Decl(coAndContraVariantInferences6.ts, 32, 11))
|
||||
>value : Symbol(value, Decl(coAndContraVariantInferences6.ts, 33, 40))
|
||||
|
||||
declare const props: any[];
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 35, 13))
|
||||
|
||||
declare const stat: any;
|
||||
>stat : Symbol(stat, Decl(coAndContraVariantInferences6.ts, 36, 13))
|
||||
|
||||
[].push.apply(props, stat.properties);
|
||||
>[].push.apply : Symbol(CallableFunction.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>[].push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>apply : Symbol(CallableFunction.apply, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>props : Symbol(props, Decl(coAndContraVariantInferences6.ts, 35, 13))
|
||||
>stat : Symbol(stat, Decl(coAndContraVariantInferences6.ts, 36, 13))
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
//// [tests/cases/compiler/coAndContraVariantInferences6.ts] ////
|
||||
|
||||
=== coAndContraVariantInferences6.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/57911
|
||||
|
||||
interface ExactProps {
|
||||
value: "A" | "B";
|
||||
>value : "A" | "B"
|
||||
}
|
||||
interface FunctionComponent<P = {}> {
|
||||
(props: P): ReactElement<any> | null;
|
||||
>props : P
|
||||
}
|
||||
declare class Component<P> {
|
||||
>Component : Component<P>
|
||||
|
||||
constructor(props: P);
|
||||
>props : P
|
||||
}
|
||||
interface ComponentClass<P = {}> {
|
||||
new (props: P): Component<P>;
|
||||
>props : P
|
||||
}
|
||||
|
||||
interface ReactElement<
|
||||
T extends string | JSXElementConstructor<any> =
|
||||
| string
|
||||
| JSXElementConstructor<any>,
|
||||
> {
|
||||
type: T;
|
||||
>type : T
|
||||
}
|
||||
|
||||
type JSXElementConstructor<P> =
|
||||
>JSXElementConstructor : JSXElementConstructor<P>
|
||||
|
||||
| ((props: P) => ReactElement<any> | null)
|
||||
>props : P
|
||||
|
||||
| (new (props: P) => Component<any>);
|
||||
>props : P
|
||||
|
||||
declare function createElementIsolated<P extends {}>(
|
||||
>createElementIsolated : <P extends {}>(type: FunctionComponent<P> | ComponentClass<P> | string, props?: P | null) => void
|
||||
|
||||
type: FunctionComponent<P> | ComponentClass<P> | string,
|
||||
>type : string | FunctionComponent<P> | ComponentClass<P>
|
||||
|
||||
props?: P | null,
|
||||
>props : P | null | undefined
|
||||
|
||||
): void;
|
||||
|
||||
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
|
||||
>WrapperIsolated : JSXElementConstructor<ExactProps>
|
||||
|
||||
createElementIsolated(WrapperIsolated, { value: "C" });
|
||||
>createElementIsolated(WrapperIsolated, { value: "C" }) : void
|
||||
>createElementIsolated : <P extends {}>(type: string | FunctionComponent<P> | ComponentClass<P>, props?: P | null | undefined) => void
|
||||
>WrapperIsolated : JSXElementConstructor<ExactProps>
|
||||
>{ value: "C" } : { value: "C"; }
|
||||
>value : "C"
|
||||
>"C" : "C"
|
||||
|
||||
declare const props: any[];
|
||||
>props : any[]
|
||||
|
||||
declare const stat: any;
|
||||
>stat : any
|
||||
|
||||
[].push.apply(props, stat.properties);
|
||||
>[].push.apply(props, stat.properties) : number
|
||||
>[].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; }
|
||||
>[].push : (...items: never[]) => number
|
||||
>[] : never[]
|
||||
>push : (...items: never[]) => number
|
||||
>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; }
|
||||
>props : any[]
|
||||
>stat.properties : any
|
||||
>stat : any
|
||||
>properties : any
|
||||
|
||||
41
tests/cases/compiler/coAndContraVariantInferences6.ts
Normal file
41
tests/cases/compiler/coAndContraVariantInferences6.ts
Normal file
@ -0,0 +1,41 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/57911
|
||||
|
||||
interface ExactProps {
|
||||
value: "A" | "B";
|
||||
}
|
||||
interface FunctionComponent<P = {}> {
|
||||
(props: P): ReactElement<any> | null;
|
||||
}
|
||||
declare class Component<P> {
|
||||
constructor(props: P);
|
||||
}
|
||||
interface ComponentClass<P = {}> {
|
||||
new (props: P): Component<P>;
|
||||
}
|
||||
|
||||
interface ReactElement<
|
||||
T extends string | JSXElementConstructor<any> =
|
||||
| string
|
||||
| JSXElementConstructor<any>,
|
||||
> {
|
||||
type: T;
|
||||
}
|
||||
|
||||
type JSXElementConstructor<P> =
|
||||
| ((props: P) => ReactElement<any> | null)
|
||||
| (new (props: P) => Component<any>);
|
||||
|
||||
declare function createElementIsolated<P extends {}>(
|
||||
type: FunctionComponent<P> | ComponentClass<P> | string,
|
||||
props?: P | null,
|
||||
): void;
|
||||
|
||||
declare let WrapperIsolated: JSXElementConstructor<ExactProps>;
|
||||
createElementIsolated(WrapperIsolated, { value: "C" });
|
||||
|
||||
declare const props: any[];
|
||||
declare const stat: any;
|
||||
[].push.apply(props, stat.properties);
|
||||
Loading…
x
Reference in New Issue
Block a user