Skip to content

Narrow from 'any' with all type guards #5011

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

Closed
wants to merge 6 commits into from

Conversation

DanielRosenwasser
Copy link
Member

Fixes #4432.

@tinganho
Copy link
Contributor

I was about to submit the same PR yesterday. tinganho@3ea297d

@DanielRosenwasser
Copy link
Member Author

Sorry you went through that, I didn't mean to step on anyone's feet! Though in the future if you'd like to take an assigned bug on, just post a quick message on the issue saying so.

@tinganho
Copy link
Contributor

Oh no problem. I was just thinking it was a small change and that I could quickly submit it. I didn't lose that much time. I will send a small notification next time.

@@ -31,6 +41,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru
if (obj2 instanceof A) { // can't narrow type from 'any'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment out dated. please update.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2015

LGTM, a few comments though

  • please update test comments
  • please run the RWC tests and verify if there are any unexpected failures/ failures we need to know about
  • log a spec issue to update the spec.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2015

We should close this one as well.

@vvakame
Copy link
Contributor

vvakame commented Dec 23, 2015

Is this commit already merged in master? I ❤️ this changes.

@DanielRosenwasser
Copy link
Member Author

@vvakame, no, the problem is that instanceof type guards can have bad behavior when you do something like x instanceof Object - now you can access effectively nothing. By extension, user-defined type guards are weakened down to instanceof guards. It's not optimal, but we're still considering the issue.

@vvakame
Copy link
Contributor

vvakame commented Dec 28, 2015

I understand!

@mhegazy mhegazy deleted the narrowAnyWithAllTypeGuards branch November 2, 2017 21:05
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants