angular-cn/packages/language-service/test
Keen Yee Liau 81241af7ac fix(language-service): Suggest ? and ! operator on nullable receiver (#35200)
Under strict mode, the language service fails to typecheck nullable
symbols that have already been verified to be non-null.

This generates incorrect (false positive) and confusing diagnostics
for users.

To work around this issue in the short term, this commit changes the
diagnostic message from an error to a suggestion, and prompts users to
use the safe navigation operator (?) or non-null assertion operator (!).

For example, instead of

```typescript
{{ optional && optional.toString() }}
```

the following is cleaner:

```typescript
{{ optional?.toString() }}
{{ optional!.toString() }}
```

Note that with this change, users who legitimately make a typo in their
code will no longer see an error. I think this is acceptable, since
false positive is worse than false negative. However, if users follow
the suggestion, add ? or ! to their code, then the error will be surfaced.
This seems a reasonable trade-off.

References:

1. Safe navigation operator (?)
   https://angular.io/guide/template-syntax#the-safe-navigation-operator----and-null-property-paths
2. Non-null assertion operator (!)
   https://angular.io/guide/template-syntax#the-non-null-assertion-operator---

PR closes https://github.com/angular/angular/pull/35070
PR closes https://github.com/angular/vscode-ng-language-service/issues/589

PR Close #35200
2020-02-10 16:43:44 -08:00
..
project fix(language-service): Suggest ? and ! operator on nullable receiver (#35200) 2020-02-10 16:43:44 -08:00
BUILD.bazel test: setup circular dependency tests for all entry points (#34774) 2020-01-23 11:36:40 -08:00
completions_spec.ts feat(language-service): completions for output $event properties in (#34570) 2020-01-28 09:07:43 -08:00
definitions_spec.ts fix(language-service): prune duplicate returned definitions (#34995) 2020-01-29 12:21:04 -08:00
diagnostics_spec.ts fix(language-service): Suggest ? and ! operator on nullable receiver (#35200) 2020-02-10 16:43:44 -08:00
expression_diagnostics_spec.ts fix(language-service): Suggest ? and ! operator on nullable receiver (#35200) 2020-02-10 16:43:44 -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 feat(language-service): provide hover for microsyntax in structural directive (#34847) 2020-01-27 10:47:46 -08: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 refactor(language-service): Consistent naming between ts and ng LanguageService (#34888) 2020-01-22 14:36:04 -05:00
mocks.ts refactor(language-service): cleanup of low-hanging TODOs (#34784) 2020-01-21 13:09:30 -05:00
reflector_host_spec.ts test(language-service): remove MockData from MockTypescriptHost (#32752) 2019-09-18 15:29:25 -07: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 fix(language-service): Remove getExternalFiles() (#34260) 2019-12-05 13:13:20 -08:00
typescript_host_spec.ts refactor(language-service): Avoid leaking host outside of LanguageService (#34941) 2020-01-24 15:53:52 -08:00
typescript_symbols_spec.ts fix(compiler-cli): Refactor getTsTypeFromBuiltinType (#33778) 2019-11-15 10:43:41 -08:00
utils_spec.ts fix(language-service): Diagnostic span should point to class name (#34932) 2020-01-23 15:55:44 -08:00