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

TS2532 when class member assigned to local variable #26628

Closed
val-o opened this issue Aug 23, 2018 · 3 comments
Closed

TS2532 when class member assigned to local variable #26628

val-o opened this issue Aug 23, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@val-o
Copy link

val-o commented Aug 23, 2018

TS version: 3.0.1

Hi, I have weird situation. The code below seems pretty simple to infer that myVar cannot be null or undefined, but I am still getting this error (TS2532). Is ts compiler not capable to do this yet?
Please ignore render and console being underlined red, those are tslint errors.
Thanks.
P.S. Sorry if this question was asked before, I look through all issues related to this error code.

image

@val-o val-o changed the title TS2532 when class member to local variable TS2532 when class member assigned to local variable Aug 23, 2018
@AlCalzone
Copy link
Contributor

I don't recall the prior issues, but AFAIK typescript does not narrow based on the value of other variables. If you used

if (this.myVar) { ... }

you wouldn't get the error. I'm assuming this is a simplified repro, as you could always just remove the |null from the type declaration (after all, myVar is readonly).

@mattmccutchen
Copy link
Contributor

AlCalzone is right. Duplicate of #24865.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 23, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants