mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
Fix double error on invalid delete of readonly property (#55449)
This commit is contained in:
committed by
GitHub
parent
fecbae5d2e
commit
98d7e0b936
@@ -36713,7 +36713,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
if (isReadonlySymbol(symbol)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
}
|
||||
checkDeleteExpressionMustBeOptional(expr, symbol);
|
||||
else {
|
||||
checkDeleteExpressionMustBeOptional(expr, symbol);
|
||||
}
|
||||
}
|
||||
return booleanType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
deleteReadonlyInStrictNullChecks.ts(3,8): error TS2704: The operand of a 'delete' operator cannot be a read-only property.
|
||||
|
||||
|
||||
==== deleteReadonlyInStrictNullChecks.ts (1 errors) ====
|
||||
interface Function { readonly name: string; }
|
||||
class Foo {}
|
||||
delete Foo.name;
|
||||
~~~~~~~~
|
||||
!!! error TS2704: The operand of a 'delete' operator cannot be a read-only property.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts] ////
|
||||
|
||||
//// [deleteReadonlyInStrictNullChecks.ts]
|
||||
interface Function { readonly name: string; }
|
||||
class Foo {}
|
||||
delete Foo.name;
|
||||
|
||||
|
||||
//// [deleteReadonlyInStrictNullChecks.js]
|
||||
var Foo = /** @class */ (function () {
|
||||
function Foo() {
|
||||
}
|
||||
return Foo;
|
||||
}());
|
||||
delete Foo.name;
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts] ////
|
||||
|
||||
=== deleteReadonlyInStrictNullChecks.ts ===
|
||||
interface Function { readonly name: string; }
|
||||
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(deleteReadonlyInStrictNullChecks.ts, 0, 0))
|
||||
>name : Symbol(Function.name, Decl(deleteReadonlyInStrictNullChecks.ts, 0, 20))
|
||||
|
||||
class Foo {}
|
||||
>Foo : Symbol(Foo, Decl(deleteReadonlyInStrictNullChecks.ts, 0, 45))
|
||||
|
||||
delete Foo.name;
|
||||
>Foo.name : Symbol(Function.name, Decl(deleteReadonlyInStrictNullChecks.ts, 0, 20))
|
||||
>Foo : Symbol(Foo, Decl(deleteReadonlyInStrictNullChecks.ts, 0, 45))
|
||||
>name : Symbol(Function.name, Decl(deleteReadonlyInStrictNullChecks.ts, 0, 20))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts] ////
|
||||
|
||||
=== deleteReadonlyInStrictNullChecks.ts ===
|
||||
interface Function { readonly name: string; }
|
||||
>name : string
|
||||
|
||||
class Foo {}
|
||||
>Foo : Foo
|
||||
|
||||
delete Foo.name;
|
||||
>delete Foo.name : boolean
|
||||
>Foo.name : string
|
||||
>Foo : typeof Foo
|
||||
>name : string
|
||||
|
||||
5
tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts
Normal file
5
tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
interface Function { readonly name: string; }
|
||||
class Foo {}
|
||||
delete Foo.name;
|
||||
Reference in New Issue
Block a user