erik.gh
erik.gh
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
wait is args generic?
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
catch what?
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
i personally would just go with type annotated variables if that works
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
yeah that's what i thought
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
that is my guess
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
but there is no real way around that unless you were to split your object into multiple individually inferable function parameters
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
i think deep inference of generic objects is what causes your issues
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
yes because it's the nested type of your object that causes typescript to narrow too early
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
in a way that you tell typescript that rec.a is not actually of type { foo: string } but of type T['a']
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
so you will need to widen it in any form
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
i think the whole issue you are having is typescript narrowing the nested type of a generic too early
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
that's interesting
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
yes i think that would in fact be the same as annotating it
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
while not necessarily being of that type
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
because in some way this forces an identifier or attribute to be of type x
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
i personally don't like type assertions. i try to dodge them as much as i can
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
yes you can also inline the type that does not make a difference
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
i think the important part is that it does not force the type on the attribute
62 replies
TTCTheo's Typesafe Cult
Created by Arduano on 6/12/2024 in #questions
Typescript generic field selection assumes type incorrectly
oh okay
62 replies