We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Motivation: want to support mixin-like patterns
type Constructor = new (...args: any[]) => T; class Base { constructor(public x: number, public y: number) {} } class Derived extends Base { constructor(x: number, y: number, public z: number) { super(x, y); } } function Tagged<T extends Constructor<Base>>(superClass: T) { return class extends superClass { _tag: string; constructor(...args: any[]) { super(...args); this._tag = "hello"; this.x } } }
Problems: substitutability is not guaranteed between the new type and a type parameter.
Right now this is modeled with intersections.
T & U & V
T
U
V
(...args) => XXX
(x, y, z) => Derived
C
(...args: any[]) => C
T & C
...args: string[]
any[]
(...args: any[]) => XXX
Issues: what about generic constructors?
Can we allow code that derives from any?
any
Current rules:
override
--noImplicitOverride
static
override abstract
let x = {}; // add stuff to `x`
Another pattern:
var x = window.x || {}
Mainly for existing JavaScript patterns.
Out of time.
The text was updated successfully, but these errors were encountered:
Re: override abstract I think the decision was to allow to override an abstract method, but not with another abstract method. i.e.:
abstract class A { abstract m() {} } abstract class B extends A { // Error: cannot combine 'override' with 'abstract' override abstract m(x?: boolean) {} // OK abstract m(x?: boolean) {} } class C extends B { // Error: needs 'override' (assuming --noImplicitOverride) m(x?: boolean) {} // Error: signature mismatch m(x?: string) {} // OK override m(x?: boolean) {} }
Sorry, something went wrong.
No branches or pull requests
Allow class to extend from generic type parameters (#4890)
Motivation: want to support mixin-like patterns
Problems: substitutability is not guaranteed between the new type and a type parameter.
Right now this is modeled with intersections.
T & U & V
has signatures ofT
followed by those ofU
followed by those ofV
.(...args) => XXX
signature, take other signatures and intersect the return type.T
has a signature(x, y, z) => Derived
C
has type:(...args: any[]) => C
T & C
has type (x, y, z) => C & Derived...args: string[]
?any[]
(...args: any[]) => XXX
only changes things if it's the latter type in the intersection.(...args: any[]) => XXX
as first overload.Issues: what about generic constructors?
Can we allow code that derives from
any
?Override keyword (#13217)
Current rules:
override
is only allowed on class property declarations.--noImplicitOverride
method.override
.override
static
members?override abstract
methods?override
.Expando object support
Another pattern:
Mainly for existing JavaScript patterns.
Out of time.
The text was updated successfully, but these errors were encountered: