angular-docs-cn/packages/language-service
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
..
bundles fix(language-service): Simplify resolution logic in banner (#34262) 2019-12-06 10:27:30 -08:00
src fix(language-service): Suggest ? and ! operator on nullable receiver (#35200) 2020-02-10 16:43:44 -08:00
test fix(language-service): Suggest ? and ! operator on nullable receiver (#35200) 2020-02-10 16:43:44 -08:00
BUILD.bazel build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34736) 2020-01-15 14:58:07 -05: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