Skip to content

Commit a72a9aa

Browse files
authored
Merge pull request #15669 from Microsoft/simplify-js-check-in-index-constraint-errors
Simplify js check in index constraint errors
2 parents 47bd4d3 + 2e9143a commit a72a9aa

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20361,7 +20361,7 @@ namespace ts {
2036120361
// this allows to rule out cases when both property and indexer are inherited from the base class
2036220362
let errorNode: Node;
2036320363
if (propDeclaration &&
20364-
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty ||
20364+
(propDeclaration.kind === SyntaxKind.BinaryExpression ||
2036520365
propDeclaration.name.kind === SyntaxKind.ComputedPropertyName ||
2036620366
prop.parent === containingType.symbol)) {
2036720367
errorNode = propDeclaration;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
tests/cases/compiler/weird.js(1,1): error TS2304: Cannot find name 'someFunction'.
2+
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: Supplied parameters do not match any signature of call target.
4+
tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly has an 'any' type.
5+
6+
7+
==== tests/cases/compiler/weird.js (4 errors) ====
8+
someFunction(function(BaseClass) {
9+
~~~~~~~~~~~~
10+
!!! error TS2304: Cannot find name 'someFunction'.
11+
~~~~~~~~~
12+
!!! error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
13+
'use strict';
14+
const DEFAULT_MESSAGE = "nop!";
15+
class Hello extends BaseClass {
16+
constructor() {
17+
super();
18+
~~~~~~~
19+
!!! error TS2346: Supplied parameters do not match any signature of call target.
20+
this.foo = "bar";
21+
}
22+
_render(error) {
23+
~~~~~
24+
!!! error TS7006: Parameter 'error' implicitly has an 'any' type.
25+
const message = error.message || DEFAULT_MESSAGE;
26+
}
27+
}
28+
});
29+

tests/baselines/reference/checkIndexConstraintOfJavascriptClassExpression.js

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
// @Filename: weird.js
22
// @allowJs: true
3+
// @checkJs: true
4+
// @strict: true
5+
// @noEmit: true
36
// @out: foo.js
47
someFunction(function(BaseClass) {
5-
class Hello extends BaseClass {
6-
constructor() {
7-
this.foo = "bar";
8-
}
9-
}
8+
'use strict';
9+
const DEFAULT_MESSAGE = "nop!";
10+
class Hello extends BaseClass {
11+
constructor() {
12+
super();
13+
this.foo = "bar";
14+
}
15+
_render(error) {
16+
const message = error.message || DEFAULT_MESSAGE;
17+
}
18+
}
1019
});

0 commit comments

Comments
 (0)