-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore method bivariance in the subtype and strict subtype relationships
Fix #41977
- Loading branch information
1 parent
3037443
commit 376a03b
Showing
27 changed files
with
372 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/subtypeReduceBivariance1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
tests/cases/compiler/subtypeReduceBivariance1.ts(11,51): error TS2322: Type '(a: number) => void' is not assignable to type '(a: string | number) => void'. | ||
Types of parameters 'a' and 'a' are incompatible. | ||
Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/subtypeReduceBivariance1.ts (1 errors) ==== | ||
interface S { | ||
f(a: number | string): void; | ||
} | ||
declare const S: S; | ||
function g(a: number): void { } | ||
|
||
// Force type resolution | ||
g; | ||
S.f; | ||
|
||
const arr: Array<(a: number | string) => void> = [g, S.f]; | ||
~ | ||
!!! error TS2322: Type '(a: number) => void' is not assignable to type '(a: string | number) => void'. | ||
!!! error TS2322: Types of parameters 'a' and 'a' are incompatible. | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [subtypeReduceBivariance1.ts] | ||
interface S { | ||
f(a: number | string): void; | ||
} | ||
declare const S: S; | ||
function g(a: number): void { } | ||
|
||
// Force type resolution | ||
g; | ||
S.f; | ||
|
||
const arr: Array<(a: number | string) => void> = [g, S.f]; | ||
|
||
//// [subtypeReduceBivariance1.js] | ||
function g(a) { } | ||
// Force type resolution | ||
g; | ||
S.f; | ||
var arr = [g, S.f]; |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/subtypeReduceBivariance1.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== tests/cases/compiler/subtypeReduceBivariance1.ts === | ||
interface S { | ||
>S : Symbol(S, Decl(subtypeReduceBivariance1.ts, 0, 0), Decl(subtypeReduceBivariance1.ts, 3, 13)) | ||
|
||
f(a: number | string): void; | ||
>f : Symbol(S.f, Decl(subtypeReduceBivariance1.ts, 0, 13)) | ||
>a : Symbol(a, Decl(subtypeReduceBivariance1.ts, 1, 6)) | ||
} | ||
declare const S: S; | ||
>S : Symbol(S, Decl(subtypeReduceBivariance1.ts, 0, 0), Decl(subtypeReduceBivariance1.ts, 3, 13)) | ||
>S : Symbol(S, Decl(subtypeReduceBivariance1.ts, 0, 0), Decl(subtypeReduceBivariance1.ts, 3, 13)) | ||
|
||
function g(a: number): void { } | ||
>g : Symbol(g, Decl(subtypeReduceBivariance1.ts, 3, 19)) | ||
>a : Symbol(a, Decl(subtypeReduceBivariance1.ts, 4, 11)) | ||
|
||
// Force type resolution | ||
g; | ||
>g : Symbol(g, Decl(subtypeReduceBivariance1.ts, 3, 19)) | ||
|
||
S.f; | ||
>S.f : Symbol(S.f, Decl(subtypeReduceBivariance1.ts, 0, 13)) | ||
>S : Symbol(S, Decl(subtypeReduceBivariance1.ts, 0, 0), Decl(subtypeReduceBivariance1.ts, 3, 13)) | ||
>f : Symbol(S.f, Decl(subtypeReduceBivariance1.ts, 0, 13)) | ||
|
||
const arr: Array<(a: number | string) => void> = [g, S.f]; | ||
>arr : Symbol(arr, Decl(subtypeReduceBivariance1.ts, 10, 5)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>a : Symbol(a, Decl(subtypeReduceBivariance1.ts, 10, 18)) | ||
>g : Symbol(g, Decl(subtypeReduceBivariance1.ts, 3, 19)) | ||
>S.f : Symbol(S.f, Decl(subtypeReduceBivariance1.ts, 0, 13)) | ||
>S : Symbol(S, Decl(subtypeReduceBivariance1.ts, 0, 0), Decl(subtypeReduceBivariance1.ts, 3, 13)) | ||
>f : Symbol(S.f, Decl(subtypeReduceBivariance1.ts, 0, 13)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== tests/cases/compiler/subtypeReduceBivariance1.ts === | ||
interface S { | ||
f(a: number | string): void; | ||
>f : (a: number | string) => void | ||
>a : string | number | ||
} | ||
declare const S: S; | ||
>S : S | ||
|
||
function g(a: number): void { } | ||
>g : (a: number) => void | ||
>a : number | ||
|
||
// Force type resolution | ||
g; | ||
>g : (a: number) => void | ||
|
||
S.f; | ||
>S.f : (a: string | number) => void | ||
>S : S | ||
>f : (a: string | number) => void | ||
|
||
const arr: Array<(a: number | string) => void> = [g, S.f]; | ||
>arr : ((a: number | string) => void)[] | ||
>a : string | number | ||
>[g, S.f] : ((a: number) => void)[] | ||
>g : (a: number) => void | ||
>S.f : (a: string | number) => void | ||
>S : S | ||
>f : (a: string | number) => void | ||
|
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/subtypeReduceBivariance2.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
tests/cases/compiler/subtypeReduceBivariance2.ts(11,51): error TS2322: Type '(a: number) => void' is not assignable to type '(a: string | number) => void'. | ||
Types of parameters 'a' and 'a' are incompatible. | ||
Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/subtypeReduceBivariance2.ts (1 errors) ==== | ||
interface S { | ||
f(a: number | string): void; | ||
} | ||
declare const S: S; | ||
function g(a: number): void { } | ||
|
||
// Force type resolution | ||
S.f; | ||
g; | ||
|
||
const arr: Array<(a: number | string) => void> = [g, S.f]; | ||
~ | ||
!!! error TS2322: Type '(a: number) => void' is not assignable to type '(a: string | number) => void'. | ||
!!! error TS2322: Types of parameters 'a' and 'a' are incompatible. | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. |
Oops, something went wrong.