I'm using React and AWS CDK (nodejs) by typescript for my application.
Because some parts take graphql, there are so many duplicated type definitions.
(ex. To make 'Post' feature, I have to define the related types on front and back individually now: Post, createPost, postInput... etc)
Can I share the type definition by npm private account between of them?
or Is there any method to share it?
or maybe this question can be "How React frontend developer and CDK developer communicate about their type definition?"
I want to define the types once for consistency and effectiveness.
Thanks.
(Added informations)
I'm developing an application by React frontend and AWS CDK backend. React frontend and CDK are using typescript.
and for data fetching & subscription, I'm adding some features by graphql instead of REST API. (There is another existing backend service which is not CDK and those parts are using REST API)
(I have another plan to convert this project to use AWS Amplify after sometimes because it supports autogenerated type definition, but it seems better to start with partial area without it now... not sure. I'm exploring)
Because the React frontend and CDK also use typescript, I have to define same type definitions on both of them. For example, if I want to provide 'post' feature, I need to define 'Post', 'PostInput', 'UpdatePost', 'CreatePost'... etc on the React and also on the CDK.
If there are some inconsistency which are not intended, it occurs error.
So I've guessed that maybe there are some way to share the type definition because React and my CDK project are using javascript.
That's why I mentioned the npm. I wonder if it is possible to use npm private package for sharing the type definition.
or.. is it better to use constant instead of the type definition? but it's not proper to take the typescript advantage.. right?
You can use GraphQL codegen to generate types from the schema definition.