Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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 -
hinst12993yI used TypeScript for a long time and I never ran into such problem. It have a feeling that you're coding something wrong
-
Seph693y@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. -
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.
Related Rants
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.
rant
typescript