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

type inference with if-return #7949

Closed
unional opened this issue Apr 8, 2016 · 3 comments
Closed

type inference with if-return #7949

unional opened this issue Apr 8, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@unional
Copy link
Contributor

unional commented Apr 8, 2016

TS (1.9.0-dev.20160407)

Don't know if this is possible 🌹 :

function working(param: string | string[]) {
  if (typeof param === "string") {
    // param is string
  }
  else {
    // param is string[]
  }
}

function notWorking(param: string | string[]) {
  if (typeof param === "string") {
    // param is string
    return;
   }

   // param is string | string[]
   // Can it be detected and inferred as string[] here?
}
@basarat
Copy link
Contributor

basarat commented Apr 8, 2016

This is already done as a part of the code flow analysis that Anders is doing (not on master yet) 🌹

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 8, 2016
@RyanCavanaugh
Copy link
Member

See #2388

@basarat
Copy link
Contributor

basarat commented Apr 13, 2016

@unional PR is up if you want to watch for the moment it getting merged : #8010 (comment) 🌹

image

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants