angular-cn/packages/language-service/ivy/test
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
..
legacy fix(language-service): Always attempt HTML AST to template AST conversion for LS (#41068) 2021-03-03 21:13:58 +00:00
BUILD.bazel fix(language-service): show suggestion when type inference is suboptimal (#41072) 2021-03-23 09:39:19 -07:00
adapters_spec.ts fix(language-service): LSParseConfigHost.resolve should not concat abs paths (#40242) 2021-01-06 10:54:40 -08:00
compiler_spec.ts fix(language-service): don't show external template diagnostics in ts files (#41070) 2021-03-03 21:40:50 +00:00
completions_spec.ts fix(language-service): Only provide dom completions for inline templates (#41078) 2021-03-04 14:51:06 -08:00
definitions_spec.ts refactor(language-service): migrate definitions_spec to new testing package (#40966) 2021-02-24 08:54:34 -08:00
diagnostic_spec.ts fix(language-service): show suggestion when type inference is suboptimal (#41072) 2021-03-23 09:39:19 -07:00
gettcb_spec.ts refactor(language-service): migrate gettcb_spec to new testing package (#40966) 2021-02-24 08:54:34 -08:00
quick_info_spec.ts fix(compiler-cli): add `useInlining` option to type check config (#41043) 2021-03-18 09:52:47 -07:00
references_spec.ts fix(language-service): only provide template results on reference requests (#41041) 2021-03-03 09:39:11 -08:00
type_definitions_spec.ts test(language-service): remove circular dependency (#40966) 2021-02-24 08:54:35 -08:00