Inside a file like Button.tsx
, I define the props like this:
type ButtonProps = {
label: string;
disabled?: boolean;
}
However, my editor (Visual Studio Code) is telling me that disabled
is boolean
. Not boolean | undefined
, which is what I expect because of the optional ?
.
If I specify disabled: string | boolean
, then my editor is happy to acknowledge that disabled
is a string
or a boolean
. If I change it to string | undefined
, it goes right back to thinking it’s a string.
What am I doing wrong here?