interface CustomHTMLElement {
htmlPropA: string,
htmlPropB: string,
}
interface CustomHTMLInput {
inputPropA: string,
inputPropB: string,
}
type CustomElement =
| CustomHTMLElement
| CustomHTMLInput
const element: CustomElement = {
inputPropA: 'bar', // implies that this is a CustomHTMLInput
h // intellisense shows htmlPropA, htmlPropB here, indicating it could also be a CustomHTMLElement
// and not just a CustomHTMLInput as previously implied by the presence of inputPropA
}
Even with inputPropA
already existing in the object,
intellisense will display both htmlPropA
and htmlPropB
,
potentially causing confusion about the type of the element. Is there a better way to specify the typing
so that intellisense only suggests properties for either CustomHTMLInput
or CustomHTMLElement
instead of both?