A
A
asdasdqwe2022-03-09 13:15:44
typescript
asdasdqwe, 2022-03-09 13:15:44

Type 'string' is not assignable to type '"" | «success» | warning | "error"?

Component:

interface AlertProps {
  variant: "success" | "warning" | "error" | "";
}

const Alert = ({ variant }: AlertProps) => {}


Component call:
const [alertvariant, setAlertvariant] = useState("success");

  return (
     <Alert variant={alertvariant} />
)


As a result, the error Type 'string' is not assignable to type '"" | "success" | "warning" | "error".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Azad Kichibekov, 2022-03-09
@asdasdqwe

const [alertvariant, setAlertvariant] = useState<AlertProps["variant"]>("success");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question