Is it possible to define a class that inherits from Array but has ReadonlyArray-typed instances? I tried inheriting from a value that mimics ArrayConstructor but constructs ReadonlyArray-s, however, it doesn't work because "Base constructors must all have the same return type"
const readonlyArray = Array as ArrayConstructor & {
new <t>(arrayLength?: number): readonly t[]
new <t>(arrayLength: number): readonly t[]
new <t>(...items: readonly t[]): readonly t[]
(arrayLength?: number): readonly any[]
<t>(arrayLength: number): readonly t[]
<t>(...items: t[]): readonly t[]
}
export class RangeArray<t> extends readonlyArray<t> {
// ...
}
Thanks in advance!
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.