-
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.
Add check for delete expression must be optional
- Loading branch information
Showing
14 changed files
with
618 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(2,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(3,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(6,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(7,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(10,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(11,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(14,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(15,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(16,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(19,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(20,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(23,8): error TS2790: The operand of a 'delete' operator must be optional. | ||
tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts(24,9): error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
|
||
==== tests/cases/conformance/expressions/optionalChaining/delete/deleteChain.ts (13 errors) ==== | ||
declare const o1: undefined | { b: string }; | ||
delete o1?.b; | ||
~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o1?.b); | ||
~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
declare const o2: undefined | { b: { c: string } }; | ||
delete o2?.b.c; | ||
~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o2?.b.c); | ||
~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
declare const o3: { b: undefined | { c: string } }; | ||
delete o3.b?.c; | ||
~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o3.b?.c); | ||
~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
declare const o4: { b?: { c: { d?: { e: string } } } }; | ||
delete o4.b?.c.d?.e; | ||
~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o4.b?.c.d)?.e; | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o4.b?.c.d?.e); | ||
~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
declare const o5: { b?(): { c: { d?: { e: string } } } }; | ||
delete o5.b?.().c.d?.e; | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o5.b?.().c.d?.e); | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
|
||
declare const o6: { b?: { c: { d?: { e: string } } } }; | ||
delete o6.b?.['c'].d?.['e']; | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. | ||
delete (o6.b?.['c'].d?.['e']); | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2790: The operand of a 'delete' operator must be optional. |
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).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/deleteExpressionMustBeOptional.ts(24,10): error TS2339: Property 'j' does not exist on type 'Foo'. | ||
|
||
|
||
==== tests/cases/compiler/deleteExpressionMustBeOptional.ts (1 errors) ==== | ||
interface Foo { | ||
a: number | ||
b: number | undefined | ||
c: number | null | ||
d?: number | ||
e: number | undefined | null | ||
f?: number | undefined | null | ||
g: unknown | ||
h: any | ||
i: never | ||
} | ||
|
||
declare const f: Foo | ||
|
||
delete f.a | ||
delete f.b | ||
delete f.c | ||
delete f.d | ||
delete f.e | ||
delete f.f | ||
delete f.g | ||
delete f.h | ||
delete f.i | ||
delete f.j | ||
~ | ||
!!! error TS2339: Property 'j' does not exist on type 'Foo'. |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).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,37 @@ | ||
//// [deleteExpressionMustBeOptional.ts] | ||
interface Foo { | ||
a: number | ||
b: number | undefined | ||
c: number | null | ||
d?: number | ||
e: number | undefined | null | ||
f?: number | undefined | null | ||
g: unknown | ||
h: any | ||
i: never | ||
} | ||
|
||
declare const f: Foo | ||
|
||
delete f.a | ||
delete f.b | ||
delete f.c | ||
delete f.d | ||
delete f.e | ||
delete f.f | ||
delete f.g | ||
delete f.h | ||
delete f.i | ||
delete f.j | ||
|
||
//// [deleteExpressionMustBeOptional.js] | ||
delete f.a; | ||
delete f.b; | ||
delete f.c; | ||
delete f.d; | ||
delete f.e; | ||
delete f.f; | ||
delete f.g; | ||
delete f.h; | ||
delete f.i; | ||
delete f.j; |
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).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,84 @@ | ||
=== tests/cases/compiler/deleteExpressionMustBeOptional.ts === | ||
interface Foo { | ||
>Foo : Symbol(Foo, Decl(deleteExpressionMustBeOptional.ts, 0, 0)) | ||
|
||
a: number | ||
>a : Symbol(Foo.a, Decl(deleteExpressionMustBeOptional.ts, 0, 15)) | ||
|
||
b: number | undefined | ||
>b : Symbol(Foo.b, Decl(deleteExpressionMustBeOptional.ts, 1, 13)) | ||
|
||
c: number | null | ||
>c : Symbol(Foo.c, Decl(deleteExpressionMustBeOptional.ts, 2, 25)) | ||
|
||
d?: number | ||
>d : Symbol(Foo.d, Decl(deleteExpressionMustBeOptional.ts, 3, 20)) | ||
|
||
e: number | undefined | null | ||
>e : Symbol(Foo.e, Decl(deleteExpressionMustBeOptional.ts, 4, 14)) | ||
|
||
f?: number | undefined | null | ||
>f : Symbol(Foo.f, Decl(deleteExpressionMustBeOptional.ts, 5, 32)) | ||
|
||
g: unknown | ||
>g : Symbol(Foo.g, Decl(deleteExpressionMustBeOptional.ts, 6, 33)) | ||
|
||
h: any | ||
>h : Symbol(Foo.h, Decl(deleteExpressionMustBeOptional.ts, 7, 14)) | ||
|
||
i: never | ||
>i : Symbol(Foo.i, Decl(deleteExpressionMustBeOptional.ts, 8, 10)) | ||
} | ||
|
||
declare const f: Foo | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>Foo : Symbol(Foo, Decl(deleteExpressionMustBeOptional.ts, 0, 0)) | ||
|
||
delete f.a | ||
>f.a : Symbol(Foo.a, Decl(deleteExpressionMustBeOptional.ts, 0, 15)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>a : Symbol(Foo.a, Decl(deleteExpressionMustBeOptional.ts, 0, 15)) | ||
|
||
delete f.b | ||
>f.b : Symbol(Foo.b, Decl(deleteExpressionMustBeOptional.ts, 1, 13)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>b : Symbol(Foo.b, Decl(deleteExpressionMustBeOptional.ts, 1, 13)) | ||
|
||
delete f.c | ||
>f.c : Symbol(Foo.c, Decl(deleteExpressionMustBeOptional.ts, 2, 25)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>c : Symbol(Foo.c, Decl(deleteExpressionMustBeOptional.ts, 2, 25)) | ||
|
||
delete f.d | ||
>f.d : Symbol(Foo.d, Decl(deleteExpressionMustBeOptional.ts, 3, 20)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>d : Symbol(Foo.d, Decl(deleteExpressionMustBeOptional.ts, 3, 20)) | ||
|
||
delete f.e | ||
>f.e : Symbol(Foo.e, Decl(deleteExpressionMustBeOptional.ts, 4, 14)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>e : Symbol(Foo.e, Decl(deleteExpressionMustBeOptional.ts, 4, 14)) | ||
|
||
delete f.f | ||
>f.f : Symbol(Foo.f, Decl(deleteExpressionMustBeOptional.ts, 5, 32)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>f : Symbol(Foo.f, Decl(deleteExpressionMustBeOptional.ts, 5, 32)) | ||
|
||
delete f.g | ||
>f.g : Symbol(Foo.g, Decl(deleteExpressionMustBeOptional.ts, 6, 33)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>g : Symbol(Foo.g, Decl(deleteExpressionMustBeOptional.ts, 6, 33)) | ||
|
||
delete f.h | ||
>f.h : Symbol(Foo.h, Decl(deleteExpressionMustBeOptional.ts, 7, 14)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>h : Symbol(Foo.h, Decl(deleteExpressionMustBeOptional.ts, 7, 14)) | ||
|
||
delete f.i | ||
>f.i : Symbol(Foo.i, Decl(deleteExpressionMustBeOptional.ts, 8, 10)) | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
>i : Symbol(Foo.i, Decl(deleteExpressionMustBeOptional.ts, 8, 10)) | ||
|
||
delete f.j | ||
>f : Symbol(f, Decl(deleteExpressionMustBeOptional.ts, 12, 13)) | ||
|
96 changes: 96 additions & 0 deletions
96
tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).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,96 @@ | ||
=== tests/cases/compiler/deleteExpressionMustBeOptional.ts === | ||
interface Foo { | ||
a: number | ||
>a : number | ||
|
||
b: number | undefined | ||
>b : number | ||
|
||
c: number | null | ||
>c : number | ||
>null : null | ||
|
||
d?: number | ||
>d : number | ||
|
||
e: number | undefined | null | ||
>e : number | ||
>null : null | ||
|
||
f?: number | undefined | null | ||
>f : number | ||
>null : null | ||
|
||
g: unknown | ||
>g : unknown | ||
|
||
h: any | ||
>h : any | ||
|
||
i: never | ||
>i : never | ||
} | ||
|
||
declare const f: Foo | ||
>f : Foo | ||
|
||
delete f.a | ||
>delete f.a : boolean | ||
>f.a : number | ||
>f : Foo | ||
>a : number | ||
|
||
delete f.b | ||
>delete f.b : boolean | ||
>f.b : number | ||
>f : Foo | ||
>b : number | ||
|
||
delete f.c | ||
>delete f.c : boolean | ||
>f.c : number | ||
>f : Foo | ||
>c : number | ||
|
||
delete f.d | ||
>delete f.d : boolean | ||
>f.d : number | ||
>f : Foo | ||
>d : number | ||
|
||
delete f.e | ||
>delete f.e : boolean | ||
>f.e : number | ||
>f : Foo | ||
>e : number | ||
|
||
delete f.f | ||
>delete f.f : boolean | ||
>f.f : number | ||
>f : Foo | ||
>f : number | ||
|
||
delete f.g | ||
>delete f.g : boolean | ||
>f.g : unknown | ||
>f : Foo | ||
>g : unknown | ||
|
||
delete f.h | ||
>delete f.h : boolean | ||
>f.h : any | ||
>f : Foo | ||
>h : any | ||
|
||
delete f.i | ||
>delete f.i : boolean | ||
>f.i : never | ||
>f : Foo | ||
>i : never | ||
|
||
delete f.j | ||
>delete f.j : boolean | ||
>f.j : any | ||
>f : Foo | ||
>j : any | ||
|
Oops, something went wrong.