|
|
|
|
|
by jemmyw
1250 days ago
|
|
I might agree with you but sometimes we have to type up JS code that is written in different styles to what we'd personally prefer. TS should (a) let me generate the types that are used in JS. There are areas like proxies where that's just not possible, but in this case it feels like there's a disparity between TS and JS over classes. (b) I want to work with this code in my editor without red lines all over the place on perfectly valid code. super classes don't need to 'know' about the inheriting classes for static inheritance to work. i.e. here is a simplified problem in the library I'm trying to add types to: superclass: static hasField(name) { return false }
constructor() {
if(this.constructor.hasField('id')) { ... }
}
subclass: static hasField(name) { if(name === 'id') return true; }
(it doesn't really look like that but you get the idea). That just works in JS, but in TS you get `Property 'hasField' does not exist on type 'Function'`. In the TS definition there are a couple of ways I can trick it to return the right thing for `this.constructor` but if I'm looking at a JS file in vscode with TS' checkJs flag on then this pattern should just work in my opinion.edit: And I don't think I should have to trick it, that makes the definition harder to read and essentially wrong somehow. |
|