Skip to content
Permalink
Browse files

fix(language-service): bug of accessing a string index signature usin…

…g dot notation (#34177)

PR Close #34177
  • Loading branch information
ivanwonder authored and AndrewKushnir committed Dec 2, 2019
1 parent 5f0703d commit 72a5a8cab776d976faafd2394d68ed82d13f2863
@@ -308,6 +308,10 @@ class TypeWrapper implements Symbol {
}
}

class StringIndexTypeWrappr extends TypeWrapper {
public readonly type = new TypeWrapper(this.tsType, this.context);
}

class SymbolWrapper implements Symbol {
private symbol: ts.Symbol;
private _members?: SymbolTable;
@@ -506,10 +510,11 @@ class SymbolTableWrapper implements SymbolTable {
// obj.stringIndex // equivalent to obj['stringIndex'];
//
// In this case, return the type indexed by an arbitrary string key.
const symbol = this.stringIndexType.getSymbol();
if (symbol) {
return new SymbolWrapper(symbol, this.context, this.stringIndexType);
}

// if stringIndexType is js primitive type(e.g. 'string'), the Symbol is undefined;
// and In AstType.resolvePropertyRead method, the Symbol.type should get the right type.
// so I add a new Symbol type, 'StringIndexTypeWrappr'
return new StringIndexTypeWrappr(this.stringIndexType, this.context);
}

return undefined;
@@ -180,6 +180,14 @@ describe('diagnostics', () => {
expect(diags[0].messageText)
.toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`);
});

it('should not produce errors with dot notation if stringIndexType is js primitive type',
() => {
mockHost.override(TEST_TEMPLATE, `
{{primitiveType.test}}`);
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(0);
});
});
});

@@ -192,6 +192,7 @@ export class TemplateReference {
tupleArray: [string, Hero] = ['test', this.hero];
league: Hero[][] = [this.heroes];
heroesByName: {[name: string]: Hero} = {};
primitiveType: {[name: string]: string} = {};
anyValue: any;
myClick(event: any) {}
}

0 comments on commit 72a5a8c

Please sign in to comment.
You can’t perform that action at this time.