-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assignability should check an index signature or rest type of the source
against optional properties of the target. Fix one good break in the compiler itself. Fixes #27144.
- Loading branch information
1 parent
85a3475
commit 3b5caa3
Showing
13 changed files
with
280 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/assignIndexSignatureToOptionalProperty.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,30 @@ | ||
tests/cases/compiler/assignIndexSignatureToOptionalProperty.ts(17,5): error TS2322: Type 'Bar' is not assignable to type 'Foo'. | ||
Index signature is incompatible with property 'b'. | ||
Type 'number' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/assignIndexSignatureToOptionalProperty.ts (1 errors) ==== | ||
// #27144 | ||
|
||
interface Foo { | ||
a: number; | ||
b?: string; | ||
} | ||
interface Foo2 { | ||
a: number; | ||
b?: number; | ||
} | ||
interface Bar { | ||
a: number; | ||
[n: string]: number; | ||
} | ||
let b: Bar = { a: 42, b: 43 }; | ||
// Error, index signature does not match optional property `b` | ||
let f: Foo = b; | ||
~ | ||
!!! error TS2322: Type 'Bar' is not assignable to type 'Foo'. | ||
!!! error TS2322: Index signature is incompatible with property 'b'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
// OK | ||
let f2: Foo2 = b; | ||
|
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/assignIndexSignatureToOptionalProperty.js
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,29 @@ | ||
//// [assignIndexSignatureToOptionalProperty.ts] | ||
// #27144 | ||
|
||
interface Foo { | ||
a: number; | ||
b?: string; | ||
} | ||
interface Foo2 { | ||
a: number; | ||
b?: number; | ||
} | ||
interface Bar { | ||
a: number; | ||
[n: string]: number; | ||
} | ||
let b: Bar = { a: 42, b: 43 }; | ||
// Error, index signature does not match optional property `b` | ||
let f: Foo = b; | ||
// OK | ||
let f2: Foo2 = b; | ||
|
||
|
||
//// [assignIndexSignatureToOptionalProperty.js] | ||
// #27144 | ||
var b = { a: 42, b: 43 }; | ||
// Error, index signature does not match optional property `b` | ||
var f = b; | ||
// OK | ||
var f2 = b; |
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/assignIndexSignatureToOptionalProperty.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,48 @@ | ||
=== tests/cases/compiler/assignIndexSignatureToOptionalProperty.ts === | ||
// #27144 | ||
|
||
interface Foo { | ||
>Foo : Symbol(Foo, Decl(assignIndexSignatureToOptionalProperty.ts, 0, 0)) | ||
|
||
a: number; | ||
>a : Symbol(Foo.a, Decl(assignIndexSignatureToOptionalProperty.ts, 2, 15)) | ||
|
||
b?: string; | ||
>b : Symbol(Foo.b, Decl(assignIndexSignatureToOptionalProperty.ts, 3, 14)) | ||
} | ||
interface Foo2 { | ||
>Foo2 : Symbol(Foo2, Decl(assignIndexSignatureToOptionalProperty.ts, 5, 1)) | ||
|
||
a: number; | ||
>a : Symbol(Foo2.a, Decl(assignIndexSignatureToOptionalProperty.ts, 6, 16)) | ||
|
||
b?: number; | ||
>b : Symbol(Foo2.b, Decl(assignIndexSignatureToOptionalProperty.ts, 7, 14)) | ||
} | ||
interface Bar { | ||
>Bar : Symbol(Bar, Decl(assignIndexSignatureToOptionalProperty.ts, 9, 1)) | ||
|
||
a: number; | ||
>a : Symbol(Bar.a, Decl(assignIndexSignatureToOptionalProperty.ts, 10, 15)) | ||
|
||
[n: string]: number; | ||
>n : Symbol(n, Decl(assignIndexSignatureToOptionalProperty.ts, 12, 5)) | ||
} | ||
let b: Bar = { a: 42, b: 43 }; | ||
>b : Symbol(b, Decl(assignIndexSignatureToOptionalProperty.ts, 14, 3)) | ||
>Bar : Symbol(Bar, Decl(assignIndexSignatureToOptionalProperty.ts, 9, 1)) | ||
>a : Symbol(a, Decl(assignIndexSignatureToOptionalProperty.ts, 14, 14)) | ||
>b : Symbol(b, Decl(assignIndexSignatureToOptionalProperty.ts, 14, 21)) | ||
|
||
// Error, index signature does not match optional property `b` | ||
let f: Foo = b; | ||
>f : Symbol(f, Decl(assignIndexSignatureToOptionalProperty.ts, 16, 3)) | ||
>Foo : Symbol(Foo, Decl(assignIndexSignatureToOptionalProperty.ts, 0, 0)) | ||
>b : Symbol(b, Decl(assignIndexSignatureToOptionalProperty.ts, 14, 3)) | ||
|
||
// OK | ||
let f2: Foo2 = b; | ||
>f2 : Symbol(f2, Decl(assignIndexSignatureToOptionalProperty.ts, 18, 3)) | ||
>Foo2 : Symbol(Foo2, Decl(assignIndexSignatureToOptionalProperty.ts, 5, 1)) | ||
>b : Symbol(b, Decl(assignIndexSignatureToOptionalProperty.ts, 14, 3)) | ||
|
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/assignIndexSignatureToOptionalProperty.types
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,42 @@ | ||
=== tests/cases/compiler/assignIndexSignatureToOptionalProperty.ts === | ||
// #27144 | ||
|
||
interface Foo { | ||
a: number; | ||
>a : number | ||
|
||
b?: string; | ||
>b : string | ||
} | ||
interface Foo2 { | ||
a: number; | ||
>a : number | ||
|
||
b?: number; | ||
>b : number | ||
} | ||
interface Bar { | ||
a: number; | ||
>a : number | ||
|
||
[n: string]: number; | ||
>n : string | ||
} | ||
let b: Bar = { a: 42, b: 43 }; | ||
>b : Bar | ||
>{ a: 42, b: 43 } : { a: number; b: number; } | ||
>a : number | ||
>42 : 42 | ||
>b : number | ||
>43 : 43 | ||
|
||
// Error, index signature does not match optional property `b` | ||
let f: Foo = b; | ||
>f : Foo | ||
>b : Bar | ||
|
||
// OK | ||
let f2: Foo2 = b; | ||
>f2 : Foo2 | ||
>b : Bar | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/assignRestElementToOptionalProperty.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,18 @@ | ||
tests/cases/compiler/assignRestElementToOptionalProperty.ts(5,5): error TS2322: Type '[number, ...string[]]' is not assignable to type '[number, number?, ...string[]]'. | ||
Rest element type is incompatible with property '1'. | ||
Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/assignRestElementToOptionalProperty.ts (1 errors) ==== | ||
// Inspired by #27144 | ||
|
||
let t: [number, ...string[]]; | ||
// Error, rest type of `t` does not match element 1 of `t2` | ||
let t2: [number, number?, ...string[]] = t; | ||
~~ | ||
!!! error TS2322: Type '[number, ...string[]]' is not assignable to type '[number, number?, ...string[]]'. | ||
!!! error TS2322: Rest element type is incompatible with property '1'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
// OK | ||
let t3: [number, string?, ...string[]] = t; | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/assignRestElementToOptionalProperty.js
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,17 @@ | ||
//// [assignRestElementToOptionalProperty.ts] | ||
// Inspired by #27144 | ||
|
||
let t: [number, ...string[]]; | ||
// Error, rest type of `t` does not match element 1 of `t2` | ||
let t2: [number, number?, ...string[]] = t; | ||
// OK | ||
let t3: [number, string?, ...string[]] = t; | ||
|
||
|
||
//// [assignRestElementToOptionalProperty.js] | ||
// Inspired by #27144 | ||
var t; | ||
// Error, rest type of `t` does not match element 1 of `t2` | ||
var t2 = t; | ||
// OK | ||
var t3 = t; |
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/assignRestElementToOptionalProperty.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,16 @@ | ||
=== tests/cases/compiler/assignRestElementToOptionalProperty.ts === | ||
// Inspired by #27144 | ||
|
||
let t: [number, ...string[]]; | ||
>t : Symbol(t, Decl(assignRestElementToOptionalProperty.ts, 2, 3)) | ||
|
||
// Error, rest type of `t` does not match element 1 of `t2` | ||
let t2: [number, number?, ...string[]] = t; | ||
>t2 : Symbol(t2, Decl(assignRestElementToOptionalProperty.ts, 4, 3)) | ||
>t : Symbol(t, Decl(assignRestElementToOptionalProperty.ts, 2, 3)) | ||
|
||
// OK | ||
let t3: [number, string?, ...string[]] = t; | ||
>t3 : Symbol(t3, Decl(assignRestElementToOptionalProperty.ts, 6, 3)) | ||
>t : Symbol(t, Decl(assignRestElementToOptionalProperty.ts, 2, 3)) | ||
|
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/assignRestElementToOptionalProperty.types
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,16 @@ | ||
=== tests/cases/compiler/assignRestElementToOptionalProperty.ts === | ||
// Inspired by #27144 | ||
|
||
let t: [number, ...string[]]; | ||
>t : [number, ...string[]] | ||
|
||
// Error, rest type of `t` does not match element 1 of `t2` | ||
let t2: [number, number?, ...string[]] = t; | ||
>t2 : [number, number?, ...string[]] | ||
>t : [number, ...string[]] | ||
|
||
// OK | ||
let t3: [number, string?, ...string[]] = t; | ||
>t3 : [number, string?, ...string[]] | ||
>t : [number, ...string[]] | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/compiler/assignIndexSignatureToOptionalProperty.ts
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 @@ | ||
// #27144 | ||
|
||
interface Foo { | ||
a: number; | ||
b?: string; | ||
} | ||
interface Foo2 { | ||
a: number; | ||
b?: number; | ||
} | ||
interface Bar { | ||
a: number; | ||
[n: string]: number; | ||
} | ||
let b: Bar = { a: 42, b: 43 }; | ||
// Error, index signature does not match optional property `b` | ||
let f: Foo = b; | ||
// OK | ||
let f2: Foo2 = b; |
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,7 @@ | ||
// Inspired by #27144 | ||
|
||
let t: [number, ...string[]]; | ||
// Error, rest type of `t` does not match element 1 of `t2` | ||
let t2: [number, number?, ...string[]] = t; | ||
// OK | ||
let t3: [number, string?, ...string[]] = t; |