Estoy tratando de proporcionar condicionalmente el título de la información sobre herramientas llamando a una función y usando la declaración if, pero tengo un error.
const getStatusMessage = (answer: AnswerStatus) => { if (answer == AnswerStatus.ANSWER_SUBMITTED || answer == AnswerStatus.ANSWER_PROCESSING) { return 'answers are still being processed.' } else if (answer == AnswerStatus.QUESTION_SERVED) { return "question was given to candidate but didn't answer it." } else if (answer == AnswerStatus.ANSWER_FAILED) { return 'there was a problem processing the answer of the candidate.' }}
<Tooltip placement='bottom-end' title={getStatusMessage(answer.status)}><button/></Tooltip>---MENSAJE DE ERROR---
Escriba 'cadena | undefined' no se puede asignar al tipo 'booleano | Reaccionar niño | Fragmento de reacción | ReactPortal'.
El tipo 'indefinido' no se puede asignar al tipo 'booleano | Reaccionar niño | Fragmento de reacción | ReactPortal'.ts(2322) Tooltip.d.ts(163, 3): El tipo esperado proviene de la propiedad 'título' que se declara aquí en el tipo 'IntrinsicAttributes & TooltipProps'
El error se produce porque la propiedad del título del componente Tooltip está obteniendo un valor indefinido
No cubriste el caso predeterminado cuando answer.status no está undefined .
Así que tampoco
<Tooltip placement='bottom-end' title={answer.status? getStatusMessage(answer.status) : '' }><button/></Tooltip> o un return ''; declaración en su getStatusMessage servirá.
const getStatusMessage = (answer: AnswerStatus) => { if (answer == AnswerStatus.ANSWER_SUBMITTED || answer == AnswerStatus.ANSWER_PROCESSING) { return 'answers are still being processed.' } else if (answer == AnswerStatus.QUESTION_SERVED) { return "question was given to candidate but didn't answer it." } else if (answer == AnswerStatus.ANSWER_FAILED) { return 'there was a problem processing the answer of the candidate.' } return '';