Merge pull request #15669 from Microsoft/simplify-js-check-in-index-constraint-errors

Simplify js check in index constraint errors
This commit is contained in:
Nathan Shively-Sanders
2017-05-08 13:36:54 -07:00
committed by GitHub
4 changed files with 44 additions and 38 deletions

View File

@@ -20361,7 +20361,7 @@ namespace ts {
// this allows to rule out cases when both property and indexer are inherited from the base class
let errorNode: Node;
if (propDeclaration &&
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty ||
(propDeclaration.kind === SyntaxKind.BinaryExpression ||
propDeclaration.name.kind === SyntaxKind.ComputedPropertyName ||
prop.parent === containingType.symbol)) {
errorNode = propDeclaration;

View File

@@ -0,0 +1,29 @@
tests/cases/compiler/weird.js(1,1): error TS2304: Cannot find name 'someFunction'.
tests/cases/compiler/weird.js(1,23): error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
tests/cases/compiler/weird.js(6,13): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly has an 'any' type.
==== tests/cases/compiler/weird.js (4 errors) ====
someFunction(function(BaseClass) {
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'someFunction'.
~~~~~~~~~
!!! error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
'use strict';
const DEFAULT_MESSAGE = "nop!";
class Hello extends BaseClass {
constructor() {
super();
~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
this.foo = "bar";
}
_render(error) {
~~~~~
!!! error TS7006: Parameter 'error' implicitly has an 'any' type.
const message = error.message || DEFAULT_MESSAGE;
}
}
});

View File

@@ -1,32 +0,0 @@
//// [weird.js]
someFunction(function(BaseClass) {
class Hello extends BaseClass {
constructor() {
this.foo = "bar";
}
}
});
//// [foo.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
someFunction(function (BaseClass) {
var Hello = (function (_super) {
__extends(Hello, _super);
function Hello() {
var _this = this;
_this.foo = "bar";
return _this;
}
return Hello;
}(BaseClass));
});

View File

@@ -1,10 +1,19 @@
// @Filename: weird.js
// @allowJs: true
// @checkJs: true
// @strict: true
// @noEmit: true
// @out: foo.js
someFunction(function(BaseClass) {
class Hello extends BaseClass {
constructor() {
this.foo = "bar";
}
}
'use strict';
const DEFAULT_MESSAGE = "nop!";
class Hello extends BaseClass {
constructor() {
super();
this.foo = "bar";
}
_render(error) {
const message = error.message || DEFAULT_MESSAGE;
}
}
});