Skip to content

Narrowing unknown by typeof object to object | null #26828

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

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

sheetalkamat
Copy link
Member

Fixes #26327

@DanielRosenwasser
Copy link
Member

Will this narrow to object if someone wrote the following?

function foo(x: unknown) {
    if (x && typeof x === "object") {
        x
    }
}

@sheetalkamat
Copy link
Member Author

no it does not . Can you file separate bug. That would need creating unknown type with and without undefined and/or null specifically since unknown right now contains everything it isn't narrowed at all by expressions like if (x) or if(x !== null) etc

@RyanCavanaugh RyanCavanaugh merged commit 4717ddb into master Sep 5, 2018
@sheetalkamat sheetalkamat deleted the narrowUnknownByObject branch September 6, 2018 16:50
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 this pull request may close these issues.

4 participants