Reputation: 632
Consider I have defined type:
export type RegisterInput = {
email: Scalars['String'];
age: Scalars['Int'];
password: Scalars['String'];
};
It is an automatically generated type of graphql input by a code generator.
I want to use this type to describe the initial values of the form in the front end. Using Formik something like this:
<Formik
initialValues={
{ email: '', age: null, password: '' } as RegisterInput
}
>
{...}
</Formik>
The idea is when graphql changes, the type is regenerated and typescript will complain. The problem is that obviously it is not possible to use the type for initial values since initial values can be nullable while the type RegisterInput
does not allow nullable values.
The question is: Is there a way to describe only keys of the object based on the given type in typescript?
Upvotes: 1
Views: 35
Reputation: 19524
Partial<RegisterInput>
will make all properties of the type option (possibly undefined
).
Upvotes: 1