SolidJSS
SolidJSโ€ข3y agoโ€ข
5 replies
walid

Type conditional Syntax between props

Hey folks,
is there any way to check if IOperation['content'] is of type string since JSX.Element extends from string too ? But like in a way that we know for sure that IOperation['ctx'] will def be defined ?
export interface IOperation {
  content: JSX.Element
  ctx?: (value: number) => void
}

/// ...
// `operation.ctx` possibly null here 
if (tyepof operation.content !== 'number') return operation.ctx(operations.indexOf(operation))
// ...

I'm just asking a type conditional syntax here to make IOperation['ctx'] not optional only if content is of type number
Was this page helpful?