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

Object is possibly undefined inside a closure #33319

Closed
iby opened this issue Sep 9, 2019 · 2 comments · Fixed by #56908
Closed

Object is possibly undefined inside a closure #33319

iby opened this issue Sep 9, 2019 · 2 comments · Fixed by #56908

Comments

@iby
Copy link

iby commented Sep 9, 2019

TypeScript Version: 3.7.0-dev.20190907

Search Terms: possibly undefined is:open

Code

function foo(value?: string) {
    if (value === undefined) { value = "hello"; }
    console.log(value.toUpperCase()); // OK
    setTimeout(() => value.toUpperCase(), 1); // TS2532
}

Expected behavior: Successful compilation.

Actual behavior: Compilation failing with error TS2532: Object is possibly 'undefined'..

Playground Link: www.typescriptlang.org/play/#code/…

Related Issues: #31060

@jack-williams
Copy link
Collaborator

Duplicate of #9998

@jack-williams jack-williams marked this as a duplicate of #9998 Sep 9, 2019
@iby
Copy link
Author

iby commented Sep 9, 2019

@jack-williams What are the odds finding that as a duplicate! 😄 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants