create-react-library
create-react-library copied to clipboard
Trying to use create-react-library to create a library with ts and getting an error "Property 'x' does not exist on type" with conditional props
I found the create-react-library library and wanted to use it to create a library for wallets. i've created a component that has conditional props depending of the type provided. something like this in the types :
export type CardAndroidProps =
| CardAndroidStore
| CardAndroidEvent
export type CardAndroidStore = {
type: 'store';
backgroundColor: string;
} ;
export type CardAndroidEvent= {
type: 'event';
mainTitle: string;
} ;
This way when the user calls the component and tries to pass props, depending on the type value he will be notified by the missing prop or that a prop does not exist on a the type. so this part works fine. The problem happens when trying to call "props.mainTitle" or "props.backgroundColor" in the component source code, i get this error in the compiler "Property 'mainTitle' does not exist on type" but nothing in the IDE (VScode in my case). I had to use "//@ts-ignore" each time i need to call a prop.
//@ts-ignore
console.log(props.mainTitle)
Is there a problem with the library compiler not allowing conditional props ? or is it a problem in my code ? Thx in advance.