TypeScript – How to fix: is not assignable to type, provides no match for the signature

TypeScript

TypeScript is JavaScript with syntax for types. TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

How to reproduce it

const eventProps = { setEventType, eventOptions};

<EventOptions {...eventProps}></EventOptions>

export function EventOptions(setEventType: React.Dispatch<React.SetStateAction<string>>, eventOptions: React.RefObject<HTMLDivElement>): ReactElement {
...
return <></>;
}

Error

TS2322: Type '{ setEventType: Dispatch<SetStateAction<string>>; eventOptions: RefObject<HTMLDivElement>; }' is not assignable to type 'Dispatch<SetStateAction<string>>'.
  Type '{ setEventType: Dispatch<SetStateAction<string>>; eventOptions: RefObject<HTMLDivElement>; }' provides no match for the signature '(value: SetStateAction<string>): void'.

Solution

Update definition of parameters .

export function EventOptions({ setEventType, eventOptions }: { setEventType: React.Dispatch>; eventOptions: React.RefObject }): ReactElement {
…
return <></>;
}
https://www.mldgroup.com

Vyštudovaný top manažér pôsobiaci najmä ako manažér, marketér, softvérový inžinier, konzultant, bloger, YouTuber a zatiaľ neúspešný hudobník a producent. V rámci praxe pôsobil v rôznych odvetviach na rôznych pozíciách v malých aj veľkých firmách, vrátane spoluprác a partnerstiev s významnými firmami či poradenskými spoločnosťami.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *