Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--strictNullChecks typeguard of dectructured variable does not apply to its original value #11175

Closed
ghost opened this issue Sep 27, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Sep 27, 2016

TypeScript Tools for Visual Studio: 2.0.3.0

Code

if (someObj.prop) { // typeguard tests property with dot notation
    const { prop } = someObj; // destructure property to variable
    someFnThatDontAcceptUndefined( prop ) // error TS2532 Object possibly 'undefined'
}

this also does not work

const { prop } = someObj; // destructure
if (prop) { // typeguard test for destructured
    someFnThatDontAcceptUndefined( someObj.prop ) // use with dot notation leads to Error
}

Expected behavior:
Typeguard of property accesed via dotted notation would also apply to destructured property and vice versa.

Actual behavior:
Properties destructured to variable are not tied to its value accessed via dotted notation and thus typeguard of one of them is not propagated to the other.

@Arnavion
Copy link
Contributor

Duplicate of #10846 which itself is a duplicate of #10065

@mhegazy mhegazy closed this as completed Sep 27, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 27, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants