Trying to understand the correct approach for destructuring a returned object.
Below is the TypeScript code snippet:
const id = 1;
const { film: { title, director } } = await getEvent({ id });
Encountering errors for both title
and director
with message:
Property does not exist on type film
.
Hovering over film
reveals its type:
(property) film?: {
title?: string | null | undefined;
director?: string | null | undefined;
... and 10 more ...;
} | undefined
How can I convey to the compiler that these properties do indeed exist without altering the type of title
and director
to be non-optional?