Skip to content

type guards are not working in this case #1595

Closed
@bpasero

Description

@bpasero

I am using the following example that I took directly from the blog post (http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s-new-in-the-typescript-type-system.aspx)

var x: any = "foo";
if(typeof x === 'string') {
   console.log(x.subtr(1)); // Error, 'subtr' does not exist on 'string'
}
// x is still any here
x.unknown(); // OK

I am not seeing the error or intellisense for the console.log statement.

Are type guards actually supported in this case or only for union types?

Metadata

Metadata

Assignees

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