I'm not sure if this is the right place to ask this conditional question, but can we do general types in TypeScript? I often have components like follows:
type Props = {
title: string
buttonLabel?: string
onButtonClick?: () => void
}
So I can optionally provide a string for a button and if it's provided then I also should provide what happens to it on click. However I want onButtonClick
to be mandatory if buttonLabel is provided. Some syntax like:
type Props = {
title: string
buttonLabel?: string
onButtonClick<!buttonLabel>: () => void
}
Is this available in Typescript or any other language?