Skip to content

Commit 154ac34

Browse files
authored
Allow extending any, with noImplicitAny errors (microsoft#23153)
Allow extending any, without noImplicitAny errors
1 parent 7520f95 commit 154ac34

11 files changed

Lines changed: 220 additions & 19 deletions

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17938,6 +17938,9 @@ namespace ts {
1793817938
function resolveCallExpression(node: CallExpression, candidatesOutArray: Signature[]): Signature {
1793917939
if (node.expression.kind === SyntaxKind.SuperKeyword) {
1794017940
const superType = checkSuperExpression(node.expression);
17941+
if (isTypeAny(superType)) {
17942+
return anySignature;
17943+
}
1794117944
if (superType !== unknownType) {
1794217945
// In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated
1794317946
// with the type arguments specified in the extends clause.

tests/baselines/reference/checkIndexConstraintOfJavascriptClassExpression.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
tests/cases/compiler/weird.js(1,1): error TS2304: Cannot find name 'someFunction'.
22
tests/cases/compiler/weird.js(1,23): error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
3-
tests/cases/compiler/weird.js(6,13): error TS2346: Call target does not contain any signatures.
43
tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly has an 'any' type.
54

65

7-
==== tests/cases/compiler/weird.js (4 errors) ====
6+
==== tests/cases/compiler/weird.js (3 errors) ====
87
someFunction(function(BaseClass) {
98
~~~~~~~~~~~~
109
!!! error TS2304: Cannot find name 'someFunction'.
@@ -15,8 +14,6 @@ tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly
1514
class Hello extends BaseClass {
1615
constructor() {
1716
super();
18-
~~~~~~~
19-
!!! error TS2346: Call target does not contain any signatures.
2017
this.foo = "bar";
2118
}
2219
_render(error) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
=== tests/cases/compiler/a.ts ===
2+
declare var Err: any
3+
>Err : Symbol(Err, Decl(a.ts, 0, 11))
4+
5+
class A extends Err {
6+
>A : Symbol(A, Decl(a.ts, 0, 20))
7+
>Err : Symbol(Err, Decl(a.ts, 0, 11))
8+
9+
payload: string
10+
>payload : Symbol(A.payload, Decl(a.ts, 1, 21))
11+
12+
constructor() {
13+
super(1,2,3,3,4,56)
14+
super.unknown
15+
super['unknown']
16+
}
17+
process() {
18+
>process : Symbol(A.process, Decl(a.ts, 7, 5))
19+
20+
return this.payload + "!";
21+
>this.payload : Symbol(A.payload, Decl(a.ts, 1, 21))
22+
>this : Symbol(A, Decl(a.ts, 0, 20))
23+
>payload : Symbol(A.payload, Decl(a.ts, 1, 21))
24+
}
25+
}
26+
27+
var o = {
28+
>o : Symbol(o, Decl(a.ts, 13, 3))
29+
30+
m() {
31+
>m : Symbol(m, Decl(a.ts, 13, 9))
32+
33+
super.unknown
34+
}
35+
}
36+
=== tests/cases/compiler/b.js ===
37+
class B extends Err {
38+
>B : Symbol(B, Decl(b.js, 0, 0))
39+
>Err : Symbol(Err, Decl(a.ts, 0, 11))
40+
41+
constructor() {
42+
super()
43+
this.wat = 12
44+
>this.wat : Symbol(B.wat, Decl(b.js, 2, 15))
45+
>this : Symbol(B, Decl(b.js, 0, 0))
46+
>wat : Symbol(B.wat, Decl(b.js, 2, 15))
47+
}
48+
f() {
49+
>f : Symbol(B.f, Decl(b.js, 4, 5))
50+
51+
this.wat
52+
>this.wat : Symbol(B.wat, Decl(b.js, 2, 15))
53+
>this : Symbol(B, Decl(b.js, 0, 0))
54+
>wat : Symbol(B.wat, Decl(b.js, 2, 15))
55+
56+
this.wit
57+
>this : Symbol(B, Decl(b.js, 0, 0))
58+
59+
this['wot']
60+
>this : Symbol(B, Decl(b.js, 0, 0))
61+
62+
super.alsoBad
63+
}
64+
}
65+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
=== tests/cases/compiler/a.ts ===
2+
declare var Err: any
3+
>Err : any
4+
5+
class A extends Err {
6+
>A : A
7+
>Err : any
8+
9+
payload: string
10+
>payload : string
11+
12+
constructor() {
13+
super(1,2,3,3,4,56)
14+
>super(1,2,3,3,4,56) : void
15+
>super : any
16+
>1 : 1
17+
>2 : 2
18+
>3 : 3
19+
>3 : 3
20+
>4 : 4
21+
>56 : 56
22+
23+
super.unknown
24+
>super.unknown : any
25+
>super : any
26+
>unknown : any
27+
28+
super['unknown']
29+
>super['unknown'] : any
30+
>super : any
31+
>'unknown' : "unknown"
32+
}
33+
process() {
34+
>process : () => string
35+
36+
return this.payload + "!";
37+
>this.payload + "!" : string
38+
>this.payload : string
39+
>this : this
40+
>payload : string
41+
>"!" : "!"
42+
}
43+
}
44+
45+
var o = {
46+
>o : { m(): void; }
47+
>{ m() { super.unknown }} : { m(): void; }
48+
49+
m() {
50+
>m : () => void
51+
52+
super.unknown
53+
>super.unknown : any
54+
>super : any
55+
>unknown : any
56+
}
57+
}
58+
=== tests/cases/compiler/b.js ===
59+
class B extends Err {
60+
>B : B
61+
>Err : any
62+
63+
constructor() {
64+
super()
65+
>super() : void
66+
>super : any
67+
68+
this.wat = 12
69+
>this.wat = 12 : 12
70+
>this.wat : number
71+
>this : this
72+
>wat : number
73+
>12 : 12
74+
}
75+
f() {
76+
>f : () => void
77+
78+
this.wat
79+
>this.wat : number
80+
>this : this
81+
>wat : number
82+
83+
this.wit
84+
>this.wit : any
85+
>this : this
86+
>wit : any
87+
88+
this['wot']
89+
>this['wot'] : any
90+
>this : this
91+
>'wot' : "wot"
92+
93+
super.alsoBad
94+
>super.alsoBad : any
95+
>super : any
96+
>alsoBad : any
97+
}
98+
}
99+

tests/baselines/reference/thisTypeInFunctions2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts(14,5): error TS70
3838
});
3939
extend2({
4040
init() {
41-
this // this: containing object literal type
41+
this // this: IndexedWithoutThis because of contextual typing
4242
this.mine
4343
},
4444
mine: 13,
4545
foo() {
46-
this // this: containing object literal type
46+
this // this: IndexedWithoutThis because of contextual typing
4747
this.mine
4848
}
4949
});

tests/baselines/reference/thisTypeInFunctions2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ extend1({
3333
});
3434
extend2({
3535
init() {
36-
this // this: containing object literal type
36+
this // this: IndexedWithoutThis because of contextual typing
3737
this.mine
3838
},
3939
mine: 13,
4040
foo() {
41-
this // this: containing object literal type
41+
this // this: IndexedWithoutThis because of contextual typing
4242
this.mine
4343
}
4444
});
@@ -68,12 +68,12 @@ extend1({
6868
});
6969
extend2({
7070
init: function () {
71-
this; // this: containing object literal type
71+
this; // this: IndexedWithoutThis because of contextual typing
7272
this.mine;
7373
},
7474
mine: 13,
7575
foo: function () {
76-
this; // this: containing object literal type
76+
this; // this: IndexedWithoutThis because of contextual typing
7777
this.mine;
7878
}
7979
});

tests/baselines/reference/thisTypeInFunctions2.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extend2({
8989
init() {
9090
>init : Symbol(init, Decl(thisTypeInFunctions2.ts, 32, 9))
9191

92-
this // this: containing object literal type
92+
this // this: IndexedWithoutThis because of contextual typing
9393
>this : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1))
9494

9595
this.mine
@@ -102,7 +102,7 @@ extend2({
102102
foo() {
103103
>foo : Symbol(foo, Decl(thisTypeInFunctions2.ts, 37, 13))
104104

105-
this // this: containing object literal type
105+
this // this: IndexedWithoutThis because of contextual typing
106106
>this : Symbol(IndexedWithoutThis, Decl(thisTypeInFunctions2.ts, 5, 1))
107107

108108
this.mine

tests/baselines/reference/thisTypeInFunctions2.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ extend1({
9292
}
9393
});
9494
extend2({
95-
>extend2({ init() { this // this: containing object literal type this.mine }, mine: 13, foo() { this // this: containing object literal type this.mine }}) : void
95+
>extend2({ init() { this // this: IndexedWithoutThis because of contextual typing this.mine }, mine: 13, foo() { this // this: IndexedWithoutThis because of contextual typing this.mine }}) : void
9696
>extend2 : (args: IndexedWithoutThis) => void
97-
>{ init() { this // this: containing object literal type this.mine }, mine: 13, foo() { this // this: containing object literal type this.mine }} : { init(): void; mine: number; foo(): void; }
97+
>{ init() { this // this: IndexedWithoutThis because of contextual typing this.mine }, mine: 13, foo() { this // this: IndexedWithoutThis because of contextual typing this.mine }} : { init(): void; mine: number; foo(): void; }
9898

9999
init() {
100100
>init : () => void
101101

102-
this // this: containing object literal type
102+
this // this: IndexedWithoutThis because of contextual typing
103103
>this : IndexedWithoutThis
104104

105105
this.mine
@@ -115,7 +115,7 @@ extend2({
115115
foo() {
116116
>foo : () => void
117117

118-
this // this: containing object literal type
118+
this // this: IndexedWithoutThis because of contextual typing
119119
>this : IndexedWithoutThis
120120

121121
this.mine
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noImplicitAny: true
5+
// @target: es6
6+
// @Filename: a.ts
7+
declare var Err: any
8+
class A extends Err {
9+
payload: string
10+
constructor() {
11+
super(1,2,3,3,4,56)
12+
super.unknown
13+
super['unknown']
14+
}
15+
process() {
16+
return this.payload + "!";
17+
}
18+
}
19+
20+
var o = {
21+
m() {
22+
super.unknown
23+
}
24+
}
25+
// @Filename: b.js
26+
class B extends Err {
27+
constructor() {
28+
super()
29+
this.wat = 12
30+
}
31+
f() {
32+
this.wat
33+
this.wit
34+
this['wot']
35+
super.alsoBad
36+
}
37+
}

tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ extend1({
3535
});
3636
extend2({
3737
init() {
38-
this // this: containing object literal type
38+
this // this: IndexedWithoutThis because of contextual typing
3939
this.mine
4040
},
4141
mine: 13,
4242
foo() {
43-
this // this: containing object literal type
43+
this // this: IndexedWithoutThis because of contextual typing
4444
this.mine
4545
}
4646
});

0 commit comments

Comments
 (0)