Skip to content

Commit 70a15bd

Browse files
committed
Need to add a couple of errors and squash one
Will update after checking out other branch for a minute
1 parent ac96739 commit 70a15bd

File tree

6 files changed

+95
-19
lines changed

6 files changed

+95
-19
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29477,7 +29477,6 @@ namespace ts {
2947729477
// type declaration, derived and base resolve to the same symbol even in the case of generic classes.
2947829478
if (derived === base) {
2947929479
// derived class inherits base without override/redeclaration
29480-
2948129480
const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!;
2948229481

2948329482
// It is an error to inherit an abstract member without implementing it or being declared abstract.
@@ -29522,13 +29521,19 @@ namespace ts {
2952229521
if (derived.flags & SymbolFlags.Property
2952329522
&& !(derived.flags & SymbolFlags.Transient)
2952429523
&& !(baseDeclarationFlags & ModifierFlags.Abstract)
29524+
&& !(derivedDeclarationFlags & ModifierFlags.Ambient)
2952529525
&& !derived.declarations.some(d => d.flags & NodeFlags.Ambient)
2952629526
&& derived.declarations.some(d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer)) {
2952729527
const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override;
2952829528
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
2952929529
}
2953029530
continue;
2953129531
}
29532+
if (derivedDeclarationFlags & ModifiersFlags.Ambient) {
29533+
const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override;
29534+
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
29535+
continue;
29536+
}
2953229537

2953329538
let errorMessage: DiagnosticMessage;
2953429539
if (isPrototypeProperty(base)) {
@@ -32518,7 +32523,7 @@ namespace ts {
3251832523
else if (flags & ModifierFlags.Async) {
3251932524
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
3252032525
}
32521-
else if (isClassLike(node.parent)) {
32526+
else if (isClassLike(node.parent) && !isPropertyDeclaration(node)) {
3252232527
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
3252332528
}
3252432529
else if (node.kind === SyntaxKind.Parameter) {
@@ -33627,7 +33632,7 @@ namespace ts {
3362733632
}
3362833633
}
3362933634

33630-
if (node.flags & NodeFlags.Ambient) {
33635+
if (node.flags & NodeFlags.Ambient || getModifierFlags(node) & ModifierFlags.Ambient) {
3363133636
checkAmbientInitializer(node);
3363233637
}
3363333638

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(5,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override.
2-
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(11,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
2+
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(14,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
33

44

55
==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (2 errors) ====
66
class A {
77
property = 'x';
88
}
99
class B extends A {
10-
property; // should be an error
10+
property; // error
1111
~~~~~~~~
1212
!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override.
1313
}
14+
class BD extends A {
15+
declare property; // still has implicit any
16+
}
1417
class C {
1518
p: string;
1619
}
1720
class D extends C {
18-
p: 'hi'; // should also be an error?
21+
p: 'hi'; // error
1922
~
2023
!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
2124
}
25+
class DD extends C {
26+
declare p: 'bye'; // ok
27+
}
2228

tests/baselines/reference/derivedUninitializedPropertyDeclaration.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ class A {
33
property = 'x';
44
}
55
class B extends A {
6-
property; // should be an error
6+
property; // error
7+
}
8+
class BD extends A {
9+
declare property; // still has implicit any
710
}
811
class C {
912
p: string;
1013
}
1114
class D extends C {
12-
p: 'hi'; // should also be an error?
15+
p: 'hi'; // error
16+
}
17+
class DD extends C {
18+
declare p: 'bye'; // ok
1319
}
1420

1521

@@ -40,6 +46,13 @@ var B = /** @class */ (function (_super) {
4046
}
4147
return B;
4248
}(A));
49+
var BD = /** @class */ (function (_super) {
50+
__extends(BD, _super);
51+
function BD() {
52+
return _super !== null && _super.apply(this, arguments) || this;
53+
}
54+
return BD;
55+
}(A));
4356
var C = /** @class */ (function () {
4457
function C() {
4558
}
@@ -52,3 +65,10 @@ var D = /** @class */ (function (_super) {
5265
}
5366
return D;
5467
}(C));
68+
var DD = /** @class */ (function (_super) {
69+
__extends(DD, _super);
70+
function DD() {
71+
return _super !== null && _super.apply(this, arguments) || this;
72+
}
73+
return DD;
74+
}(C));

tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ class B extends A {
99
>B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 2, 1))
1010
>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0))
1111

12-
property; // should be an error
12+
property; // error
1313
>property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 19))
1414
}
15+
class BD extends A {
16+
>BD : Symbol(BD, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
17+
>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0))
18+
19+
declare property; // still has implicit any
20+
>property : Symbol(BD.property, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 20))
21+
}
1522
class C {
16-
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
23+
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
1724

1825
p: string;
19-
>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 9))
26+
>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 9))
2027
}
2128
class D extends C {
22-
>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
23-
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
29+
>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 11, 1))
30+
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
31+
32+
p: 'hi'; // error
33+
>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 12, 19))
34+
}
35+
class DD extends C {
36+
>DD : Symbol(DD, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 1))
37+
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
2438

25-
p: 'hi'; // should also be an error?
26-
>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 19))
39+
declare p: 'bye'; // ok
40+
>p : Symbol(DD.p, Decl(derivedUninitializedPropertyDeclaration.ts, 15, 20))
2741
}
2842

tests/baselines/reference/derivedUninitializedPropertyDeclaration.types

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ class B extends A {
1010
>B : B
1111
>A : A
1212

13-
property; // should be an error
13+
property; // error
14+
>property : any
15+
}
16+
class BD extends A {
17+
>BD : BD
18+
>A : A
19+
20+
declare property; // still has implicit any
1421
>property : any
1522
}
1623
class C {
@@ -23,7 +30,14 @@ class D extends C {
2330
>D : D
2431
>C : C
2532

26-
p: 'hi'; // should also be an error?
33+
p: 'hi'; // error
2734
>p : "hi"
2835
}
36+
class DD extends C {
37+
>DD : DD
38+
>C : C
39+
40+
declare p: 'bye'; // ok
41+
>p : "bye"
42+
}
2943

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
// @strict: true
12
class A {
23
property = 'x';
4+
m() { return 1 }
35
}
46
class B extends A {
5-
property; // should be an error
7+
property; // error
68
}
9+
class BD extends A {
10+
declare property; // still has implicit any, but is implicitly initialised
11+
}
12+
class BDBang extends A {
13+
declare property!; // still has implicit any, doesn't need !, but has it anyway
14+
}
15+
class BOther extends A {
16+
declare m() { return 2 } // not allowed on methods
17+
declare nonce; // only allowed when exists in base
18+
declare property = 'y' // initialiser not allowed with declare
19+
}
20+
721
class C {
822
p: string;
923
}
1024
class D extends C {
11-
p: 'hi'; // should also be an error?
25+
p: 'hi'; // error
26+
}
27+
class DD extends C {
28+
declare p: 'bye'; // ok
1229
}

0 commit comments

Comments
 (0)