#Typing return type for react's `useMemo()`
14 messages · Page 1 of 1 (latest)
!ts
import { useMemo } from "react";
// ^^^^^^^
// Cannot find module 'react' or its corresponding type declarations.
type Foo = { a: string };
useMemo<Foo>(() => {
return { a: "", b: "" };
}, []);
useMemo((): Foo => {
return { a: "", b: "" };
// ^^^^^
// Type '{ a: string; b: string; }' is not assignable to type 'Foo'.
// Object literal may only specify known properties, and 'b' does not exist in type 'Foo'.
}, []);