Add check for delete expression must be optional
This commit is contained in:
parent
eb105efdcd
commit
76937c3b1a
14 changed files with 620 additions and 4 deletions
|
@ -27564,14 +27564,27 @@ namespace ts {
|
|||
if (expr.kind === SyntaxKind.PropertyAccessExpression && isPrivateIdentifier((expr as PropertyAccessExpression).name)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_private_identifier);
|
||||
}
|
||||
|
||||
const links = getNodeLinks(expr);
|
||||
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
|
||||
if (symbol && isReadonlySymbol(symbol)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
if (symbol) {
|
||||
if (isReadonlySymbol(symbol)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
}
|
||||
|
||||
checkDeleteExpressionMustBeOptional(expr, getTypeOfSymbol(symbol));
|
||||
}
|
||||
|
||||
return booleanType;
|
||||
}
|
||||
|
||||
function checkDeleteExpressionMustBeOptional(expr: AccessExpression, type: Type) {
|
||||
const AnyOrUnknownOrNeverFlags = TypeFlags.AnyOrUnknown | TypeFlags.Never;
|
||||
if (strictNullChecks && !(type.flags & AnyOrUnknownOrNeverFlags) && !(getFalsyFlags(type) & TypeFlags.Undefined)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_optional);
|
||||
}
|
||||
}
|
||||
|
||||
function checkTypeOfExpression(node: TypeOfExpression): Type {
|
||||
checkExpression(node.expression);
|
||||
return typeofType;
|
||||
|
|
|
@ -2963,6 +2963,10 @@
|
|||
"category": "Error",
|
||||
"code": 2789
|
||||
},
|
||||
"The operand of a 'delete' operator must be optional.": {
|
||||
"category": "Error",
|
||||
"code": 2790
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(10,12): error TS2790: The operand of a 'delete' operator must be optional.
|
||||
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error TS2703: The operand of a 'delete' operator must be a property reference.
|
||||
|
||||
|
||||
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (1 errors) ====
|
||||
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (2 errors) ====
|
||||
function f() {
|
||||
let x: { a?: number | string, b: number | string } = { b: 1 };
|
||||
x.a;
|
||||
|
@ -12,6 +13,8 @@ tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error T
|
|||
x.b;
|
||||
delete x.a;
|
||||
delete x.b;
|
||||
~~~
|
||||
!!! error TS2790: The operand of a 'delete' operator must be optional.
|
||||
x.a;
|
||||
x.b;
|
||||
x;
|
||||
|
|
66
tests/baselines/reference/deleteChain.errors.txt
Normal file
66
tests/baselines/reference/deleteChain.errors.txt
Normal file
|
@ -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.
|
|
@ -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'.
|
|
@ -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;
|
|
@ -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))
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
tests/cases/compiler/deleteExpressionMustBeOptional.ts(15,8): error TS2790: The operand of a 'delete' operator must be optional.
|
||||
tests/cases/compiler/deleteExpressionMustBeOptional.ts(17,8): error TS2790: The operand of a 'delete' operator must be optional.
|
||||
tests/cases/compiler/deleteExpressionMustBeOptional.ts(24,10): error TS2339: Property 'j' does not exist on type 'Foo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/deleteExpressionMustBeOptional.ts (3 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
|
||||
~~~
|
||||
!!! error TS2790: The operand of a 'delete' operator must be optional.
|
||||
delete f.b
|
||||
delete f.c
|
||||
~~~
|
||||
!!! error TS2790: The operand of a 'delete' operator must be optional.
|
||||
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'.
|
|
@ -0,0 +1,38 @@
|
|||
//// [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]
|
||||
"use strict";
|
||||
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;
|
|
@ -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))
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
=== tests/cases/compiler/deleteExpressionMustBeOptional.ts ===
|
||||
interface Foo {
|
||||
a: number
|
||||
>a : number
|
||||
|
||||
b: number | undefined
|
||||
>b : number | undefined
|
||||
|
||||
c: number | null
|
||||
>c : number | null
|
||||
>null : null
|
||||
|
||||
d?: number
|
||||
>d : number | undefined
|
||||
|
||||
e: number | undefined | null
|
||||
>e : number | null | undefined
|
||||
>null : null
|
||||
|
||||
f?: number | undefined | null
|
||||
>f : number | null | undefined
|
||||
>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 | undefined
|
||||
>f : Foo
|
||||
>b : number | undefined
|
||||
|
||||
delete f.c
|
||||
>delete f.c : boolean
|
||||
>f.c : number | null
|
||||
>f : Foo
|
||||
>c : number | null
|
||||
|
||||
delete f.d
|
||||
>delete f.d : boolean
|
||||
>f.d : number | undefined
|
||||
>f : Foo
|
||||
>d : number | undefined
|
||||
|
||||
delete f.e
|
||||
>delete f.e : boolean
|
||||
>f.e : number | null | undefined
|
||||
>f : Foo
|
||||
>e : number | null | undefined
|
||||
|
||||
delete f.f
|
||||
>delete f.f : boolean
|
||||
>f.f : number | null | undefined
|
||||
>f : Foo
|
||||
>f : number | null | undefined
|
||||
|
||||
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
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts(4,16): error TS2790: The operand of a 'delete' operator must be optional.
|
||||
tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts(4,16): error TS18011: The operand of a 'delete' operator cannot be a private identifier.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts (1 errors) ====
|
||||
==== tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts (2 errors) ====
|
||||
class A {
|
||||
#v = 1;
|
||||
constructor() {
|
||||
delete this.#v; // Error: The operand of a delete operator cannot be a private name.
|
||||
~~~~~~~
|
||||
!!! error TS2790: The operand of a 'delete' operator must be optional.
|
||||
~~~~~~~
|
||||
!!! error TS18011: The operand of a 'delete' operator cannot be a private identifier.
|
||||
}
|
||||
}
|
||||
|
|
26
tests/cases/compiler/deleteExpressionMustBeOptional.ts
Normal file
26
tests/cases/compiler/deleteExpressionMustBeOptional.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
// @strict: true, false
|
||||
|
||||
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
|
Loading…
Reference in a new issue