11

typescript, I HATE you!

ME: Trying to extend Subject and override Subject.subscribe(PartialObserver<T>)

ME: export class MySubject<T> extends Subject<T> {
subscribe(obs?:PartialObserver<T>): Subscription {
return super.subscribe(obs);
}
}

ME: compile
TS: Compilation error! No such method to override!

ME: load the app -- ERROR

ME: recompile
TS: Compilation error! No such method to override!

ME: load the app -- works perfectly

:confusedjackie:

Make up your mind! So is that class compileable or not???
If not -- how the fuck does it work then???
If yes -- why the fuck do you yell in my face with all those errors???

Comments
  • 0
    Is the return type of the parent subscribe method explicit?
  • 0
    @darrenrahnemoon I think so

    Observable.ts

    export class Observable<T> implements Subscribable<T> {

    /*...*/

    subscribe(observer?: PartialObserver<T>): Subscription;

    /*...*/

    }
  • 0
    I think this might happen if the signature of the methods don’t match but they have the same name. Can’t tell much from this example cuz it looks fine.
  • 2
    You had me at “typescript I hate you”…
  • 0
    Typescript is evil, it takes me 30 minutes to write the code and then 2 hours to fix all the ts compilation errors :/
  • 0
    It’s not that bad tbh helps a lllllot with cleaning up ur code. Static typing also makes it easier to code review ppls work. If it was just pure javascript I’d lose my mind code reviewing a 1000 line PR.
  • 0
    @darrenrahnemoon I agree, it's a lot better than plain js. However, the OOP-wannabe is killing me... I can't override methods I want, I can't use polymorphism freely, I can't cast types 'just like that' (why tf the 'as unknown' in the middle??), etc.

    It's more like Python in terms of OOP. But worse. IMO it's somewhere between Python and javascript oop-wise. It kind of has OOP concepts, but not quite.
  • 0
    @netikras read the docs top to bottom. I haven’t had any issues with polymorphism in TS. Also learn ur generic <T> utilities
Add Comment