angular-docs-cn/packages/language-service/test
ayazhafiz 1425e63029 fix(language-service): determine correct type for ngFor exported values (#34089)
Currently, variables of an unknown type in an `*ngFor` expression are
refined to have the type of the iterable binding of the `*ngFor`
expression. Unfortunately, this is a bug for variables aliasing
[values exported by
`*ngFor`](https://angular.io/api/common/NgForOf#local-variables),
including `index` and `first`, because they are also given the type of
the binding expression, but they are not of the binding type. For
example, in

```typescript
@Component({
  selector: 'test',
  template: `
    <div *ngFor="let hero of heroes; let i = index; let isFirst = first">
      {{ hero }}
    </div>
  `
})
export class TestComponent {
  heroes: Hero[];
}
```

The local variables `i` and `isFirst` are determined to have a type of
`Hero`, when actually their types are `number` and `boolean`,
respectively.

This commit fixes this bug by checking if the value of a variable in an
`*ngFor` expression is known to be an export and assigning the variable
the type of that export value. Only if the variable does not alias an
export is it typed with the binding value of the `*ngFor` expression.

Closes https://github.com/angular/vscode-ng-language-service/issues/460

PR Close #34089
2019-12-02 11:03:34 -08:00
..
project feat(language-service): completions support for tuple array (#33928) 2019-11-27 12:48:41 -08:00
BUILD.bazel refactor(compiler-cli): Move diagnostics files to language service (#33809) 2019-11-14 09:29:07 -08:00
completions_spec.ts feat(language-service): completions support for tuple array (#33928) 2019-11-27 12:48:41 -08:00
definitions_spec.ts fix(language-service): reset MockHost after every spec instead of creating new LS (#33200) 2019-10-16 17:49:55 -04:00
diagnostics_spec.ts fix(language-service): determine correct type for ngFor exported values (#34089) 2019-12-02 11:03:34 -08:00
expression_diagnostics_spec.ts refactor(compiler-cli): Move diagnostics files to language service (#33809) 2019-11-14 09:29:07 -08:00
global_symbols_spec.ts refactor(compiler-cli): Move diagnostics files to language service (#33809) 2019-11-14 09:29:07 -08:00
hover_spec.ts fix(language-service): Add global symbol for $any() (#33245) 2019-10-23 10:02:50 -07:00
html_info_spec.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
language_service_spec.ts fix(language-service): Remove getTemplateReferences() from LanguageService API (#33807) 2019-11-15 10:41:51 -08:00
mocks.ts refactor(compiler-cli): Move diagnostics files to language service (#33809) 2019-11-14 09:29:07 -08:00
reflector_host_spec.ts test(language-service): remove MockData from MockTypescriptHost (#32752) 2019-09-18 15:29:25 -07:00
template_references_spec.ts fix(language-service): Remove getTemplateReferences() from LanguageService API (#33807) 2019-11-15 10:41:51 -08:00
template_spec.ts test(language-service): remove MockData from MockTypescriptHost (#32752) 2019-09-18 15:29:25 -07:00
test_utils.ts fix(language-service): Recompute analyzed modules only when source files change (#33806) 2019-11-15 10:42:09 -08:00
ts_plugin_spec.ts feat(language-service): add support for text replacement (#33091) 2019-10-29 11:47:01 -07:00
typescript_host_spec.ts fix(language-service): Recompute analyzed modules only when source files change (#33806) 2019-11-15 10:42:09 -08:00
typescript_symbols_spec.ts fix(compiler-cli): Refactor getTsTypeFromBuiltinType (#33778) 2019-11-15 10:43:41 -08:00
utils_spec.ts refactor(language-service): Omit typechecking for finding directives (#32156) 2019-08-16 09:58:28 -07:00