Get type from Input type or Input Ref #339
Answered
by
hayes
MartinPELCAT
asked this question in
Q&A
-
Hello, I have an Input export const AddressInput = builder.inputType('AddressInput', {
fields: t => ({
uuid: t.string({ required: false }),
street: t.string({ required: false }),
city: t.string({ required: false }),
zipCode: t.string({ required: false }),
country: t.string({ required: false }),
}),
}); When i get it on the resolver, it's all good, but how can i pass it to another function ? type AddressInputType = ??? So i can do something like this const address: AddressInputType = {
uuid: "",
street: "",
city: "",
zipCode: "",
} BTW : the discord link is not working for me |
Beta Was this translation helpful? Give feedback.
Answered by
hayes
Mar 2, 2022
Replies: 2 comments 2 replies
-
I will use the input ref and declare the type myself my bad 😄 |
Beta Was this translation helpful? Give feedback.
0 replies
-
The easiest option is probably just to define a helper to extract the type like this: import { InputRef } from '@pothos/core';
type ShapeFromInput<T> = T extends InputRef<infer U> ? U : never;
export type AddressInputType = ShapeFromInput<typeof AddressInput>; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hayes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The easiest option is probably just to define a helper to extract the type like this: