4
Seph
3y

FUUUCK TYPESCRIPT

It can't handle this function: `(arg) => arg` without kicking around a bunch of generics.

https://stackoverflow.com/questions...

This is ridiculous. The generics system on Typescript is complete trash, the amount of things it's unable to handle are unbelievable, and I feel like I'm taking crazy pills when I'm supposed to just accept that they couldn't possibly have done better.

Seriously, if I was one of the developers and I saw an issue like this, I wouldn't defend it; I'd be embarrassed.

Comments
  • 6
    I feel like I'm missing something... The top answer on SO makes sense to me

    type Foo = <T>() => T; // A function that can take any T
    type Foo<T> = () => T; // A function that takes one specific T
  • 4
    I used TypeScript for a long time and I never ran into such problem. It have a feeling that you're coding something wrong
  • 0
    @hinst I've been using typescript for 3 years, and guarantee I'm in 99th percentile for understanding it.

    The fact that you never ran into this specific issue is fortunate, but doesn't make the issue non-existent.
  • 1
    @12bitfloat Theres no such thing as a function that can take any T.

    That's the issue.

    Sure if you define T it works, but you can't say: give me any function that returns the object it gets.

    That's crazy. It's totally crazy.
  • 0
    @Seph Ah that's what you mean. Yeah that seems like an issue
  • 0
    I dont understand why the top one doesnt work, C++ lets you do it
  • 1
    Wait -

    So why isnt the following working for you?

    type ObjGetter<T> = (s: T) => T;

    Since you provide it as arguments, the same type you gave as argument must be returned.

    Remember, typescript does NOT exist to make sure the objects are the same instances and point to the same memory. Typescripts job is to ensure these objects look the same.
Add Comment