Running TS 5.5.2. Here is the setup, a simple React component that accepts an optional array of strings.
type Props = {
list?: string[];
};
function ListComponent({ list }: Props) {
return (
<ul>
{list?.map((string) => <li>{string}</li>}
</ul>
);
}
This code fails linting at maybeList.data ?? undefined
:
function ParentComponent() {
const maybeList: { data: string[] | null } = client.list.get.useQuery();
return (
<ListComponent
list={maybeList.data ?? undefined} // Error: Unsafe assignment of an `any` value. @typescript-eslint/no-unsafe-assignment
/>
);
}
But this code succeeds maybeList.data ?? []
:
function ParentComponent() {
const maybeList: { data: string[] | null } = client.list.get.useQuery();
return (
<ListComponent
list={maybeList.data ?? []}
/>
);
}
I cannot understand how maybeList.data ?? undefined
is being interpreted as any
. Is this a bug? Or do I not understand TS?