angular-cn/packages/language-service
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
..
bundles build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607) 2019-11-06 19:56:57 +00:00
src fix(language-service): determine correct type for ngFor exported values (#34089) 2019-12-02 11:03:34 -08:00
test fix(language-service): determine correct type for ngFor exported values (#34089) 2019-12-02 11:03:34 -08:00
BUILD.bazel build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607) 2019-11-06 19:56:57 +00:00
index.ts build: roll up to named .js files rather than 'index.js' (#19190) 2017-09-19 16:59:18 -07:00
language-service.ts build: refactor ambient node & jasmine types so they are only included where needed (#25491) 2018-08-16 13:46:43 -07:00
package.json build: set up all packages to publish via wombot proxy (#33747) 2019-11-13 11:34:33 -08:00