Closed
Description
TypeScript Version: 3.8.0-dev.20191115
Search Terms:
subclass property inference string literal tuple type
Code
class Base {
readonly x: 'a' | 'b' = 'a';
readonly y: readonly [number, number] = [1, 2];
}
class Sub extends Base {
x = 'b';
y = [3, 4];
}
Expected behavior:
It should pass. The type checker should use the requirement from the base class to inform the subclass property inference, similar to how normal assignment works:
let x: 'a' | 'b' = 'a';
let y: readonly [number, number] = [1, 2];
x = 'b';
y = [3, 4];
Actual behavior:
(property) Sub.x: string
Property 'x' in type 'Sub' is not assignable to the same property in base type 'Base'.
Type 'string' is not assignable to type '"a" | "b"'.(2416)
(property) Sub.y: number[]
Property 'y' in type 'Sub' is not assignable to the same property in base type 'Base'.
Type 'number[]' is missing the following properties from type 'readonly [number, number]': 0, 1(2416)
Playground Link:
Related Issues:
None found
Metadata
Metadata
Assignees
Labels
No labels