I use react with typescript.
I want to require only one parameter be accepted from prop3
| prop4
. I use a union type like this:
interface General {
prop1?: boolean
prop2?: boolean
}
interface Option1 extends General {
prop3: boolean
}
interface Option2 extends General {
prop4: boolean
}
type Option1orOtion2 = Option1 | Option2
If I get prop3
I don't want that prop4
will be accepted.
When I do that I get errors about those values. What I do worng?
export default function({
prop1 = true,
prop2 = true,
prop3 = true, // error: Property 'prop3' does not exist on type 'Option1orOtion2'
prop4 = true // error: Property 'prop4' does not exist on type 'Option1orOtion2'
}: Option1orOtion2) {
return <></>
}
EDIT: When I do that with variable there aren't errors, but let me to pass prop3
and also prop4
, and I want to get a error about it (Option1
or Option2
).
var data: Option1orOtion2 = {prop3: false, prop4: false}
Any suggestion?
Thanks in advance!