stylowanie w typescript - instrukcja warunkowa

0

przerabiam reacta na typescript i w tym pliku wyskakuje mi " Type '{ color: string; } | null' is not assignable to type 'CSSProperties | undefined'.
Type 'null' is not assignable to type 'CSSProperties | undefined'. TS2322", jak pozbyć się tego błędu?

import React from "react";

interface TaskProps {
    task: Todo;
    changeTaskStatus: changeTaskStatus;
  }

  const style= {
    color: 'red',
  }

export const Task: React.FC<TaskProps> = ({ task, changeTaskStatus}) => {
    return (
    <div>
        <p>
            <strong style={task.important ? style : null}>{task.text}</strong> - do <span>{task.date} </span>
          <button onChange={() => changeTaskStatus(task.id)}>Zostało zrobione</button>
        </p>
        </div>
        )

}
2

Jeżeli TS nie chce null (Type 'null' is not assignable to type), a Ty mu podajesz null tj. task.important ? style : null, to chce coś innego (chce CSSProperties | undefined) więc warto mu podać coś innego zamiast null.

1 użytkowników online, w tym zalogowanych: 0, gości: 1