I am a full-stack developer, mainly working with Typescript. I enjoy learning functional programming languages on the side. Fan of video games, basketball, reading and hip hop music
That would certainly work and has the benefit of autocompletion for the key but it unfortunately requires you to pass the generic types to specify what T and K should be (e.g. prop<User, "email">("email")). Without that, the code doesn't compile at all:
constprop=<T,KextendskeyofT>(k:K)=>(t:T):T[K]=>t[k]// Argument of type 'string' is not assignable to // parameter of type 'never'.prop("email")
It's actually a strangely difficult function to implement in Typescript without any tradeoffs. I have a PR open for the fp-ts library to add a prop function and we iterated over several implementations - you can see the discussion here if you're interested :)
I don't really use it unless it's inline like a function, so it satisfies my needs. PR looks good, nice type Def. Having a standalone prop function to apply later looks good!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the suggestion!
That would certainly work and has the benefit of autocompletion for the key but it unfortunately requires you to pass the generic types to specify what
T
andK
should be (e.g.prop<User, "email">("email")
). Without that, the code doesn't compile at all:It's actually a strangely difficult function to implement in Typescript without any tradeoffs. I have a PR open for the fp-ts library to add a
prop
function and we iterated over several implementations - you can see the discussion here if you're interested :)I don't really use it unless it's inline like a function, so it satisfies my needs. PR looks good, nice type Def. Having a standalone prop function to apply later looks good!