Replies: 1 comment
-
my opinion is Props: Reason, discriminated union cannot be expressed using an interface. // Props is a discriminated union of 2 object type
type Props = {
isAdmin?: false, adminData?: never
} | {
isAdmin: true, adminData: {
foo: string,
bar: number
}
}
// TYPE ERROR: because when isAdmin is false, it does not have adminData attribute.
const props: Props = {
isAdmin: false,
adminData: {
foo: 'foo',
bar: 123
}
} // interface may also be possible with the following writing style? ... 🤔
interface IPropsIsAdminTrue {
isAdmin?: false, adminData?: never
}
interface IPropsIsAdminFalse {
isAdmin: true, adminData: {
foo: string,
bar: number
}
}
const props: IPropsIsAdminTrue | IPropsIsAdminFalse |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is the conclusion we had in the admin panel template discussion
ml-opensource/admin-panel-template-reactjs#88 (comment)
Beta Was this translation helpful? Give feedback.
All reactions