IssueRaiser

`static abstract` methods and properties

This is a continuation of #14600 which had two separate features proposed in the same issue (static members in interfaces *and* abstract static class members) ## Search Terms static abstract method property properties implement concrete ## Suggestion Currently, this code is illegal: ```ts abstract class A { static abstract doSomething(): void; } // Should be OK class B extends A { static doSomething() { } } // Should be an error; non-abstract class failed to implement abstract member class C extends A { } ``` It should be legal to have `abstract static` (`static abstract`?) members. ## Use Cases (what are they?) ## Unresolved Questions **What calls of abstract static methods are allowed?** Let's say you wrote a trivial hierarchy ```ts abstract class A { static abstract doSomething(): void; } class B extends A { static doSomething() { } } ``` For an expression `x.doSomething()`, what are valid `x`s? #### Option 1: All of them Because `this` isn't generic in `static` members, we should simply allow all invocations of abstract static methods. Otherwise code like this would be illegal: ```ts abstract class A { static abstract initialize(self: A): void; static createInstance() { const a = new this(); this.initialize(a); return a; } } ``` However, this means that TypeScript would miss straight-up crashes: ```ts // Exception: 'this.initialize' is not a function A.createInstance(); ``` * **Pros**: Ergonomic * **Cons**: Literally a

Posted by RyanCavanaugh on Oct 16, 2019, 4:42 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Software)

`static abstract` methods and properties

RyanCavanaughOct 16, 2019, 4:42 PM

This is a continuation of #14600 which had two separate features proposed in the same issue (static members in interfaces *and* abstract static class members) ## Search Terms static abstract method property properties implement concrete ## Suggestion Currently, this code is illegal: ```ts abstract class A { static abstract doSomething(): void; } // Should be OK class B extends A { static doSomething() { } } // Should be an error; non-abstract class failed to implement abstract member class C extends A { } ``` It should be legal to have `abstract static` (`static abstract`?) members. ## Use Cases (what are they?) ## Unresolved Questions **What calls of abstract static methods are allowed?** Let's say you wrote a trivial hierarchy ```ts abstract class A { static abstract doSomething(): void; } class B extends A { static doSomething() { } } ``` For an expression `x.doSomething()`, what are valid `x`s? #### Option 1: All of them Because `this` isn't generic in `static` members, we should simply allow all invocations of abstract static methods. Otherwise code like this would be illegal: ```ts abstract class A { static abstract initialize(self: A): void; static createInstance() { const a = new this(); this.initialize(a); return a; } } ``` However, this means that TypeScript would miss straight-up crashes: ```ts // Exception: 'this.initialize' is not a function A.createInstance(); ``` * **Pros**: Ergonomic * **Cons**: Literally a

Comments (0)

No comments yet. Start the discussion.

Comment on this issue