-
Hey there, super excited about Hotscript. Thanks so much for sharing it @gvergnaud. I have an object that looks like this: type Filter = {
booking: {
startTime: { id: string }
},
// other types here...
} On another type, I have the nested dot path: const startTimePath = 'booking.startTime' satisfies DotPath<Filter> I now want to "unfurl" these back an object, where I give a dot path and a value, and it constructs that object for me: type Sort = 'desc' | 'asc'
const startTimePath = 'booking.startTime' satisfies DotPath<Filter>
// something like DotPathKey is what I'm looking for
const order: DotPathKey<Filter, typeof startTimePath, Sort> = {
booking: {
startTime: 'asc'
},
} If I weren't using dot paths, this would be easy, since I could just use const order: { [key in keyof Filter]: Value } = {
booking: { sort: 'desc' }
} |
Beta Was this translation helpful? Give feedback.
Answered by
gvergnaud
Mar 1, 2023
Replies: 1 comment
-
Hey! I think you are looking for the import * as H from 'hotscript'
type Filter = { booking: { startTime: { id: string } } }
type res1 = H.Eval<
// ^? { booking: { startTime: "asc" | "desc" } }
H.Objects.Update<"booking.startTime", "asc" | "desc", Filter>
>;
type res2 = H.Eval<
// ^? { id: string }
H.Objects.Get<"booking.startTime", Filter>
>; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
gvergnaud
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! I think you are looking for the
Object.Get
or theObjects.Update
function: Playground