Skip to content

Fix double error on invalid delete of readonly property #55449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36680,7 +36680,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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

15 changes: 15 additions & 0 deletions tests/baselines/reference/deleteReadonlyInStrictNullChecks.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions tests/baselines/reference/deleteReadonlyInStrictNullChecks.symbols
Original file line number Diff line number Diff line change
@@ -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))

15 changes: 15 additions & 0 deletions tests/baselines/reference/deleteReadonlyInStrictNullChecks.types
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/cases/compiler/deleteReadonlyInStrictNullChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @strictNullChecks: true

interface Function { readonly name: string; }
class Foo {}
delete Foo.name;