Skip to content

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

Closed
@tjhance

Description

@tjhance

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions