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

Un-necessary compile warning: TS2454 #18719

Closed
ORESoftware opened this issue Sep 23, 2017 · 3 comments
Closed

Un-necessary compile warning: TS2454 #18719

ORESoftware opened this issue Sep 23, 2017 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@ORESoftware
Copy link

Please see this screenshot:

screenshot 2017-09-23 15 41 31

In this case temp is declared already, but may never have been assigned. The if-check prevents using it, if it's not been assigned, so this compile warning may be unnecessary?

thanks

@Ghabriel
Copy link

I understand your point, but most of the time "if" statements are used to check a variable's value, not to see whether it was assigned. This warning is useful because more often than not (at least in my experience and in most professional code I've seen) that situation is indeed not the programmer's intention.

As a side note, since "temp" is only defined inside that if statement, you can merge your two conditionals (unless path.normalize() can return a falsy value, in which case you can just assign a falsy value to temp in its declaration or in the else branch anyways).

@jwbay
Copy link
Contributor

jwbay commented Sep 25, 2017

let temp: string | undefined seems more accurate for that code in strict-null-checks world, and fixes the error as well.

@aluanhaddad
Copy link
Contributor

A snippet of code that could be copied and pasted into a text buffer instead of a screenshot from an IDE is generally much more helpful.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Sep 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants