Skip to content
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25867,7 +25867,7 @@ func (c *Checker) isAssignmentToReadonlyEntity(expr *ast.Node, symbol *ast.Symbo
// Allow assignments to readonly properties within constructors of the same class declaration.
if symbol.Flags&ast.SymbolFlagsProperty != 0 && ast.IsAccessExpression(expr) && expr.Expression().Kind == ast.KindThisKeyword {
// Look for if this is the constructor for the class that `symbol` is a property of.
ctor := getContainingFunction(expr)
ctor := c.getControlFlowContainer(expr)
if ctor == nil || !ast.IsConstructorDeclaration(ctor) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ readonlyMembers.ts(16,14): error TS2540: Cannot assign to 'c' because it is a re
readonlyMembers.ts(18,18): error TS2540: Cannot assign to 'a' because it is a read-only property.
readonlyMembers.ts(19,18): error TS2540: Cannot assign to 'b' because it is a read-only property.
readonlyMembers.ts(20,18): error TS2540: Cannot assign to 'c' because it is a read-only property.
readonlyMembers.ts(23,18): error TS2540: Cannot assign to 'a' because it is a read-only property.
readonlyMembers.ts(24,18): error TS2540: Cannot assign to 'b' because it is a read-only property.
readonlyMembers.ts(25,18): error TS2540: Cannot assign to 'c' because it is a read-only property.
readonlyMembers.ts(29,14): error TS2540: Cannot assign to 'a' because it is a read-only property.
readonlyMembers.ts(30,14): error TS2540: Cannot assign to 'b' because it is a read-only property.
Expand All @@ -18,7 +16,7 @@ readonlyMembers.ts(66,1): error TS2542: Index signature in type '{ readonly [x:
readonlyMembers.ts(69,1): error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading.


==== readonlyMembers.ts (18 errors) ====
==== readonlyMembers.ts (16 errors) ====
interface X {
readonly a: number;
readonly b?: number;
Expand Down Expand Up @@ -54,11 +52,7 @@ readonlyMembers.ts(69,1): error TS2542: Index signature in type '{ readonly [x:
};
(() => {
this.a = 1; // Ok
~
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
this.b = 1; // Ok
~
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
this.c = 1; // Error
~
!!! error TS2540: Cannot assign to 'c' because it is a read-only property.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ class C {

this.a = 1; // Ok
>this.a = 1 : 1
>this.a : any
>this.a : number
>this : this
>a : any
>a : number
>1 : 1

this.b = 1; // Ok
>this.b = 1 : 1
>this.b : any
>this.b : 1
>this : this
>b : any
>b : 1
>1 : 1

this.c = 1; // Error
Expand Down

This file was deleted.