Skip to content

In finally block, local variable is incorrectly typed as never. #11665

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
tjhance opened this issue Oct 15, 2016 · 1 comment · Fixed by #11675
Closed

In finally block, local variable is incorrectly typed as never. #11665

tjhance opened this issue Oct 15, 2016 · 1 comment · Fixed by #11675
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tjhance
Copy link

tjhance commented Oct 15, 2016

TypeScript Version: 2.0.3

Code

With --strictNullChecks,

class A {
  constructor() { }
  method() { }
}

let a: A | null = null;

try {
  a = new A();
} finally {
  if (a) {
    a.method();
  }
}

Expected behavior:

I expect this to compile. TypeScript should be able to deduce that a can be of type A at the a.method() call site.

Actual behavior:

I get an error message

Property 'method' does not exist on type 'never'.

Note that it works fine if the try and finally lines are removed.

@alitaheri
Copy link

I can confirm this with the nightly build 2.1.0-dev.20161015 too.

@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 17, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Oct 17, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Oct 17, 2016
@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants