Closed
Description
TypeScript Version: 2.6.2
Code
type Rect = {
width: number | undefined;
}
class HasARect<T extends Rect> {
rect: T;
get<K extends keyof T>(prop: K): T[K] {
return this.rect[prop];
}
getWidth(r: T): number {
return this.get("width") || 0; // Type 'undefined' is not assignable to type 'number'.
}
}
Expected behavior:
This is not a type error.
Actual behavior:
Type 'T["width"]' is not assignable to type 'number'.
Type 'number | undefined' is not assignable to type 'number'.
Type 'undefined' is not assignable to type 'number'.