1
Seph
3y

SO TIRED of the typescript generics system. I get why you can't assign Thing<Foo> to Thing<any>, I do. But also, WHAT THE FUCK!? This is such a giant waste of time having to fix everything to pass around generics that I don't care about.

I've probably spent ~500 hours of my life wrestling this stupid ass type system.

Comments
  • 1
    Huh. Are you sure that this doesn't work?
  • 2
    Might just be a bad set of types and/or shady programming practices. Perhaps @homo-lorens can comment more.
  • 0
    📌
  • 1
    That's weird, most of the time you should be able to cast generics to `Foo<any>` since `any` can be cast to and from anything else and TS only cares about the exact type when casting, not the generic or any other structure that describes it. Mind sharing your code in the TS playground?

    If you don't want to care about generics, you can also replace all occurences of the type parameter with `any`, this is essentially the same as replacing an unknown type with `void*` in C. It does mean that you have to indicate the type of variables that are initialized with return values.
  • 0
  • 0
    @M3m35terJ05h When determining whether a generic cast is legal, TypeScript looks at the properties and decides if they are castable. If OP's Foo<Bar> can't be cast to Foo<any> then that's because they're using the type arg in an unusual way, which is why I asked for the code.
  • 0
    It's really more when you start having infers as defaults for generics because otherwise you'd have to rewrite the inference everywhere it was used... I mean, I can't even get into it in a comment section save to say: typescript generics have ruined this project so many times now. And I have learned so much more about them than I ever wanted to.
  • 0
    @Seph Typescript can infer a lot, but the more you expect it to do the better you have to understand how it works. If you don't like it, use any.
  • 1
    "Use any"

    I'm a professional. And I have no problem with "get gud" being the solution to an issue.

    It's still a very under-developed system. Or do you think it has no room to grow?
  • 0
    @Seph It does have flaws most of which are fixable because they aren't in the fundamental concepts of the language. Having to learn it properly to use its full capabilities is neither fixable nor a flaw.
  • 0
    @homo-lorens Look man, I know more about Typescript than 99% of its users. If I'm struggling to type things that take less than 10 lines of code to implement in JS, it's on typescript.
Add Comment