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

Unnecessary error for "possibly undefined variable" after calling function returning never #29802

Closed
DanTup opened this issue Feb 7, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@DanTup
Copy link

DanTup commented Feb 7, 2019

I'm not sure if there's already an issue for this because I wasn't really sure how to describe it (hence the poor title). Given this code:

const someVar: number | undefined = undefined;

if (!someVar) {
	process.exit(0);
}

print(someVar.toString());

TypeScript (3.3.1) reports that someVar may be undefined on the last line. However it knows that process.exit returns never so it seems like it could know better. If I add throw on the line after process.exit then the error goes away, so I guess there is some capability to know the code can never execute that applies to throw but not when calling functions that return never.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 7, 2019
@RyanCavanaugh
Copy link
Member

Duplicate #8655

@DanTup
Copy link
Author

DanTup commented Feb 7, 2019

That issue is closed as design-limitation - does that mean this isn't fixable either? (I'm not complaining, just want to know if I should turn my temporary workaround into something nicer :-))

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

2 participants