8000 `checkClassPropertyAccess` in `getTypeForBindingElement` · creatio/TypeScript@28640c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28640c8

Browse files
committed
checkClassPropertyAccess in getTypeForBindingElement
This is probably the wrong place (a get- function rather than a check- function), but it's a starting point since it passes all tests.
1 parent 17b7c3e commit 28640c8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,8 @@ namespace ts {
26072607
// Return the inferred type for a binding element
26082608
function getTypeForBindingElement(declaration: BindingElement): Type {
26092609
const pattern = <BindingPattern>declaration.parent;
2610-
const parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
2610+
const parent = <VariableLikeDeclaration>pattern.parent;
2611+
const parentType = getTypeForBindingElementParent(parent);
26112612
// If parent has the unknown (error) type, then so does this binding element
26122613
if (parentType === unknownType) {
26132614
return unknownType;
@@ -2642,6 +2643,11 @@ namespace ts {
26422643
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
26432644
return unknownType;
26442645
}
2646+
2647+
const property = getPropertyOfType(parentType, text);
2648+
if (parent && parent.initializer && property && getParentOfSymbol(property)) {
2649+
checkClassPropertyAccess(parent, parent.initializer, parentType, property);
2650+
}
26452651
}
26462652
else {
26472653
// This elementType will be used if the specific property corresponding to this index is not
@@ -8971,13 +8977,14 @@ namespace ts {
89718977
* @param type The type of left.
89728978
* @param prop The symbol for the right hand side of the property access.
89738979
*/
8974-
function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean {
8980+
function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean {
89758981
const flags = getDeclarationFlagsFromSymbol(prop);
89768982
const declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(getParentOfSymbol(prop));
89778983

89788984
if (left.kind === SyntaxKind.SuperKeyword) {
8979-
const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ?
8980-
(<PropertyAccessExpression>node).name :
8985+
// TODO: Move this out and use it in the rest of the code
8986+
const errorNode = node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.VariableDeclaration ?
8987+
(<PropertyAccessExpression | VariableDeclaration>node).name :
89818988
(<QualifiedName>node).right;
89828989

89838990
// TS 1.0 spec (April 2014): 4.8.2

0 commit comments

Comments
 (0)
0