Skip to content

Commit 89a4b29

Browse files
author
Andy Hanson
committed
Don't report error twice for readonly in method
1 parent 4c8db9c commit 89a4b29

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17651,8 +17651,8 @@ namespace ts {
1765117651
if (flags & NodeFlags.Readonly) {
1765217652
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly");
1765317653
}
17654-
else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature &&
17655-
!(node.kind == SyntaxKind.Parameter && isParameterPropertyDeclaration(<ParameterDeclaration> node))) {
17654+
else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature && node.kind !== SyntaxKind.Parameter) {
17655+
// If node.kind === SyntaxKind.Parameter, checkParameter report an error if it's not a parameter property.
1765617656
return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature);
1765717657
}
1765817658
flags |= NodeFlags.Readonly;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts(2,14): error TS2369: A parameter property is only allowed in a constructor implementation.
2+
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts(3,9): error TS2369: A parameter property is only allowed in a constructor implementation.
23

34

4-
==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts (1 errors) ====
5+
==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts (2 errors) ====
56
declare class C{
67
constructor(readonly x: number);
78
~~~~~~~~~~~~~~~~~~
9+
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
10+
method(readonly x: number);
11+
~~~~~~~~~~~~~~~~~~
812
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
913
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//// [readonlyInAmbientClass.ts]
22
declare class C{
33
constructor(readonly x: number);
4+
method(readonly x: number);
45
}
56

67
//// [readonlyInAmbientClass.js]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
declare class C{
22
constructor(readonly x: number);
3+
method(readonly x: number);
34
}

0 commit comments

Comments
 (0)