angular-docs-cn/packages/language-service
Alex Rickabaugh 1eba57eb00 fix(language-service): show suggestion when type inference is suboptimal (#41072)
The Ivy Language Service uses the compiler's template type-checking engine,
which honors the configuration in the user's tsconfig.json. We recommend
that users upgrade to `strictTemplates` mode in their projects to take
advantage of the best possible type inference, and thus to have the best
experience in Language Service.

If a project is not using `strictTemplates`, then the compiler will not
leverage certain type inference options it has. One case where this is very
noticeable is the inference of let- variables for structural directives that
provide a template context guard (such as NgFor). Without `strictTemplates`,
these guards will not be applied and such variables will be inferred as
'any', degrading the user experience within Language Service.

This is working as designed, since the Language Service _should_ reflect
types exactly as the compiler sees them. However, the View Engine Language
Service used its own type system that _would_ infer these types even when
the compiler did not. As a result, it's confusing to some users why the
Ivy Language Service has "worse" type inference.

To address this confusion, this commit implements a suggestion diagnostic
which is shown in the Language Service for variables which could have been
narrowed via a context guard, but the type checking configuration didn't
allow it. This should make the reason why variables receive the 'any' type
as well as the action needed to improve the typings much more obvious,
improving the Language Service experience.

Fixes angular/vscode-ng-language-service#1155
Closes #41042

PR Close #41072
2021-03-23 09:39:19 -07:00
..
bundles fix(language-service): use single entry point for Ivy and View Engine (#40967) 2021-02-24 15:05:44 -08:00
ivy fix(language-service): show suggestion when type inference is suboptimal (#41072) 2021-03-23 09:39:19 -07:00
src fix(compiler): allow binding to autocomplete property on select and textarea elements (#40928) 2021-03-03 10:00:27 -08:00
test feat(core): support TypeScript 4.2 (#41158) 2021-03-17 09:10:25 -07:00
BUILD.bazel build(language-service): use 'export =' syntax for default export (#41165) 2021-03-11 14:48:33 -08:00
api.ts fix(language-service): Add plugin option to force strictTemplates (#41062) 2021-03-03 09:48:06 -08:00
build.sh build(language-service): install @angular/language-service in root node_modules (#40058) 2020-12-10 13:48:04 -08:00
index.ts build(language-service): use 'export =' syntax for default export (#41165) 2021-03-11 14:48:33 -08:00
package.json fix(language-service): use single entry point for Ivy and View Engine (#40967) 2021-02-24 15:05:44 -08:00