Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

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 #373

Open
SlamaMohamedFoued opened this issue Nov 29, 2022 · 0 comments

Comments

@SlamaMohamedFoued
Copy link

SlamaMohamedFoued commented Nov 29, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant