Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upfix(compiler-cli): use `null` in type checking of safe navigation operators #37747
+39
−9
Conversation
…rators Safe navigation operators in Angular templates will evaluate to `null` if the LHS operand is `null` or `undefined`, however the type checker would use `undefined` instead. This results in inaccurate type checking when `strictNullChecks` is enabled. BREAKING CHANGE: Using the safe navigation operator in templates will now infer the type of the expressions to be a union type including `null`, instead of `undefined` as it previously was. If TypeScript's `strictNullChecks` is enabled together with Angular's `strictTemplates` or `strictSafeNavigationTypes` you may start to see new type errors. The previous behavior of including `undefined` in the type does not correspond with the behavior at runtime, where the `null` value is used instead. Fixes #37622
|
Shouldn't TypeScript handle this operator now? As in, shouldn't this have the same semantics as the JS version? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


JoostK commentedJun 25, 2020
Safe navigation operators in Angular templates will evaluate to
nullif the LHSoperand is
nullorundefined, however the type checker would useundefinedinstead. This results in inaccurate type checking when
strictNullChecksis enabled.BREAKING CHANGE:
Using the safe navigation operator in templates will now infer the type of the
expressions to be a union type including
null, instead ofundefinedas itpreviously was. If TypeScript's
strictNullChecksis enabled together with Angular'sstrictTemplatesorstrictSafeNavigationTypesyou may start to see new type errors.The previous behavior of including
undefinedin the type does not correspond withthe behavior at runtime, where the
nullvalue is used instead.Fixes #37622