My issue is converting a type of object generated by GraphQL schema to another one that's more compact for other purposes.
The issue is that trying to move from enum that is generated for GraphQL to enum that is for the desired DTO I'v accounted the following error:
import type { Pets as GqlPets, GqlPerson } from 'gql/types';
enum Pets {
cat = "Cat";
dog = "Dog";
};
type Person = {
name: string;
email: string;
pet: Pets;
}
function gqlPersonToJson(p: GqlPerson): Person {
return {
name: p.name,
email: p.email,
pet: p.pet, //--> error Type 'GqlPets' is not assignable to type 'Pets'.
};
}
When I try to convert the enum I get the following error:
pet: GqlPerson[p.pet] as keyof typeof Pets,
Error:
TS2322: Type '"cat" | "dog"' is not assignable to type 'Pets'. Type '"cat"' is not assignable to type 'Pets'. Did you mean 'Pets.cat'?
What Am I missing?