#How to require a value to at least partially match a type?
12 messages · Page 1 of 1 (latest)
@jade summit
type HasHeight = { height: number }
function doThing = (creature: HasHeight) {}
the issue with that is, it override sthe type if that function calls a callback or something and passes it back
Oh, if doThing returns the creature at the end?
Yeah, in that case you'd want it generic:
function doThing = <T extends HasHeight>(creature: T) {
// do stuff
return creature;
}
o duh, i was close to that but over complicating it
ok the way i hav eit seems to work
basically
type HasHeight = { height: number }
function doThing = <T>(creature: T & Required<HasHeight>) {}
altho idk if the Required is really necessary
i guess so tho in case the type being passed in has height as optional