feat(language-service): completions support for indexed types (#34047)
Previously, indexing a container type would not return completions for the indexed type because for every TypeScript type, the recorded index type was always marked as `undefined`, regardless of the index signature. This PR now returns the index type of TypeScript containers with numeric or string index signatures. This allows use to generate completions for arrays and defined index types: ```typescript interface Container<T> { [key: string]: T; } const ctr: Container<T>; ctr['stringKey']. // gives `T.` completions const arr: T[]; arr[0]. // gives `T.` completions ``` Note that this does _not_ provide completions for properties indexed by string literals, e.g. ```typescript interface Container<T> { foo: T; } const ctr: Container<T>; ctr['foo']. // does not give `T.` completions ``` Closes angular/vscode-ng-language-service#110 Closes angular/vscode-ng-language-service#277 PR Close #34047
This commit is contained in:

committed by
Matias Niemelä

parent
d228801af4
commit
8a565c8814
@ -127,6 +127,15 @@ describe('diagnostics', () => {
|
||||
expect(diags).toEqual([]);
|
||||
});
|
||||
|
||||
it('should produce diagnostics for invalid index type property access', () => {
|
||||
mockHost.override(TEST_TEMPLATE, `
|
||||
{{heroes[0].badProperty}}`);
|
||||
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
|
||||
expect(diags.length).toBe(1);
|
||||
expect(diags[0].messageText)
|
||||
.toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`);
|
||||
});
|
||||
|
||||
describe('in expression-cases.ts', () => {
|
||||
it('should report access to an unknown field', () => {
|
||||
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
||||
|
Reference in New Issue
Block a user