Repository navigation
Filter undefined only in binding patterns in parameters w/initialiser - #38116
Merged
Nathan Shively-Sanders (sandersn) merged 1 commit intoApr 22, 2020
Conversation
initialiser. But this is only correct when the initialiser is for a
parameter. For example:
```ts
declare let x: { s: string } | undefined;
const { s } = x;
```
This PR removes undefined from the type of a binding pattern only when
the binding pattern's parent is a parameter. This fixes the regression
from 3.8. However, it's still not the ideal fix; we should be able to
use control flow to solve this problem. Consider:
```ts
const { s }: { s: string } | undefined = { s: 'hi' }
declare function f({ s }: { s: string } | undefined = { s: 'hi' }): void
```
Neither line should have an error, but the first does in 3.8 and after
this change.
Nathan Shively-Sanders (sandersn)
requested review from
Andrew Branch (andrewbranch) and
Wesley Wigham (weswigham)
April 22, 2020 16:37
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Apr 22, 2020
Nathan Shively-Sanders (sandersn)
deleted the
filter-undefined-only-from-binding-elts-in-params
branch
April 22, 2020 17:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#37309 removes undefined from the type of any binding pattern whose parent has an initialiser. But this is only correct when the initialiser is for a parameter. Here's a counter-example:
This PR removes undefined from the type of a binding pattern only when
the binding pattern's parent is a parameter. This fixes the regression
from 3.8. However, it's still not the ideal fix; we should be able to
use control flow to solve this problem. Consider:
Neither line should have an error, but the first does in 3.8 and after
this change.
Fixes #38110