-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
This may be a dupe of #11664 though that deals with a type union and this is purely inheritance.
TypeScript Version: 2.3.2
Code
abstract class Value {
readonly valueType: number;
abstract value(): any;
}
class NullValue extends Value {
valueType = 0;
value(): any {
return null;
}
}
class NumberValue extends Value {
valueType = 1;
constructor(readonly num: number) { super(); }
value(): any {
return this.num;
}
}
function process(node: Value) {
if (node instanceof NullValue) {
console.log('Null!')
} else if (node instanceof NumberValue) {
// Produces: TS2339: Property 'num' does not exist on type 'never'.
console.log('NumberValue', node.num);
}
}
Expected behavior: No errors.
Actual behavior: Error:
test.ts(29,37): error TS2339: Property 'num' does not exist on type 'never'.
I can "solve" the issue by adding a dummy readonly foo = null;
field to the NullValue class.
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue