diff --git a/tests/baselines/reference/coAndContraVariantInferences6.errors.txt b/tests/baselines/reference/coAndContraVariantInferences6.errors.txt new file mode 100644 index 0000000000000..3da1e7759f40d --- /dev/null +++ b/tests/baselines/reference/coAndContraVariantInferences6.errors.txt @@ -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

{ + (props: P): ReactElement | null; + } + declare class Component

{ + constructor(props: P); + } + interface ComponentClass

{ + new (props: P): Component

; + } + + interface ReactElement< + T extends string | JSXElementConstructor = + | string + | JSXElementConstructor, + > { + type: T; + } + + type JSXElementConstructor

= + | ((props: P) => ReactElement | null) + | (new (props: P) => Component); + + declare function createElementIsolated

( + type: FunctionComponent

| ComponentClass

| string, + props?: P | null, + ): void; + + declare let WrapperIsolated: JSXElementConstructor; + 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); + \ No newline at end of file diff --git a/tests/baselines/reference/coAndContraVariantInferences6.symbols b/tests/baselines/reference/coAndContraVariantInferences6.symbols new file mode 100644 index 0000000000000..4046a60430813 --- /dev/null +++ b/tests/baselines/reference/coAndContraVariantInferences6.symbols @@ -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

{ +>FunctionComponent : Symbol(FunctionComponent, Decl(coAndContraVariantInferences6.ts, 4, 1)) +>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 5, 28)) + + (props: P): ReactElement | 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

{ +>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

{ +>ComponentClass : Symbol(ComponentClass, Decl(coAndContraVariantInferences6.ts, 10, 1)) +>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 11, 25)) + + new (props: P): Component

; +>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 = +>T : Symbol(T, Decl(coAndContraVariantInferences6.ts, 15, 23)) +>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1)) + + | string + | JSXElementConstructor, +>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

= +>JSXElementConstructor : Symbol(JSXElementConstructor, Decl(coAndContraVariantInferences6.ts, 21, 1)) +>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 23, 27)) + + | ((props: P) => ReactElement | 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); +>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

( +>createElementIsolated : Symbol(createElementIsolated, Decl(coAndContraVariantInferences6.ts, 25, 39)) +>P : Symbol(P, Decl(coAndContraVariantInferences6.ts, 27, 39)) + + type: FunctionComponent

| ComponentClass

| 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; +>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)) + diff --git a/tests/baselines/reference/coAndContraVariantInferences6.types b/tests/baselines/reference/coAndContraVariantInferences6.types new file mode 100644 index 0000000000000..d32bb033374ff --- /dev/null +++ b/tests/baselines/reference/coAndContraVariantInferences6.types @@ -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

{ + (props: P): ReactElement | null; +>props : P +} +declare class Component

{ +>Component : Component

+ + constructor(props: P); +>props : P +} +interface ComponentClass

{ + new (props: P): Component

; +>props : P +} + +interface ReactElement< + T extends string | JSXElementConstructor = + | string + | JSXElementConstructor, +> { + type: T; +>type : T +} + +type JSXElementConstructor

= +>JSXElementConstructor : JSXElementConstructor

+ + | ((props: P) => ReactElement | null) +>props : P + + | (new (props: P) => Component); +>props : P + +declare function createElementIsolated

( +>createElementIsolated :

(type: FunctionComponent

| ComponentClass

| string, props?: P | null) => void + + type: FunctionComponent

| ComponentClass

| string, +>type : string | FunctionComponent

| ComponentClass

+ + props?: P | null, +>props : P | null | undefined + +): void; + +declare let WrapperIsolated: JSXElementConstructor; +>WrapperIsolated : JSXElementConstructor + +createElementIsolated(WrapperIsolated, { value: "C" }); +>createElementIsolated(WrapperIsolated, { value: "C" }) : void +>createElementIsolated :

(type: string | FunctionComponent

| ComponentClass

, props?: P | null | undefined) => void +>WrapperIsolated : JSXElementConstructor +>{ 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 : { (this: (this: T) => R, thisArg: T): R; (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 : { (this: (this: T) => R, thisArg: T): R; (this: (this: T_1, ...args: A) => R_1, thisArg: T_1, args: A): R_1; } +>props : any[] +>stat.properties : any +>stat : any +>properties : any + diff --git a/tests/cases/compiler/coAndContraVariantInferences6.ts b/tests/cases/compiler/coAndContraVariantInferences6.ts new file mode 100644 index 0000000000000..10b27976b51a3 --- /dev/null +++ b/tests/cases/compiler/coAndContraVariantInferences6.ts @@ -0,0 +1,41 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/57911 + +interface ExactProps { + value: "A" | "B"; +} +interface FunctionComponent

{ + (props: P): ReactElement | null; +} +declare class Component

{ + constructor(props: P); +} +interface ComponentClass

{ + new (props: P): Component

; +} + +interface ReactElement< + T extends string | JSXElementConstructor = + | string + | JSXElementConstructor, +> { + type: T; +} + +type JSXElementConstructor

= + | ((props: P) => ReactElement | null) + | (new (props: P) => Component); + +declare function createElementIsolated

( + type: FunctionComponent

| ComponentClass

| string, + props?: P | null, +): void; + +declare let WrapperIsolated: JSXElementConstructor; +createElementIsolated(WrapperIsolated, { value: "C" }); + +declare const props: any[]; +declare const stat: any; +[].push.apply(props, stat.properties);