-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did npm install -g typescript@next to check that this also happens with the latest version.
After some confusion and debugging it appears that the bug happens because the class Empty has no methods. If I add a random dummy method to Empty the code compiles again.
TypeScript Version: 2.1.0-dev.20160915
Code
export type FingerTree<A> = Empty | Single<A>;
export class Empty {
constructor() {};
}
export class Single<A> {
constructor(
public nested: boolean
) {};
}
export function test(t: FingerTree<any>): boolean {
if (t instanceof Empty) {
return true;
} else {
return t.nested;
}
}Expected behavior:
Code compiles without errors and t has the type Singe<any> in the else clause in test.
Actual behavior:
t has the type never in the else clause and I get` the compile error:
test.ts(17,14): error TS2339: Property 'nested' does not exist on type 'never'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue