Encountering a TypeScript error while trying to import JsonifyObject in the Remix 2.9.2 route code below...
Argument of type '
JsonifyObject<IdAndDate>
' is not assignable to parameter of type 'IdAndDate
'.
Struggling to figure out how to effectively import JsonifyObject:
import { useLoaderData } from "@remix-run/react";
type IdAndDate = {
id: number;
date: Date;
};
export default function Component() {
//
const idAndDate = useLoaderData<typeof loader>();
// This part works fine, with idAndDate.date showing as string due to serialization...
//return (<div>{idAndDate.id}: {idAndDate.date}</div>);
// However, this encounter an error --
// "Argument of type 'JsonifyObject<IdAndDate>' is not assignable to parameter of type 'IdAndDate'."
// -- and I'm unable to figure out how to import JsonifyObject :\
return <div>{formatIdAndDate(idAndDate)}</div>;
}
export function loader(): IdAndDate {
return { id: 42, date: new Date() };
}
function formatIdAndDate(idAndDate: IdAndDate): string {
return `${idAndDate.id}: ${idAndDate.date}`;
}
Attempted solution:
import { JsonifyObject } from "@remix-run/server-runtime/dist/jsonify"
Resulting in the error:
The module '"@remix-run/server-runtime/dist/jsonify"' declares 'JsonifyObject' locally, but it is not exported.
I am at a loss since it is not externally exported either.
Avoiding the usage of as IdAndDate
to preserve the recognition by JsonifiyObject that the date is serialized as a string.
(Acknowledging the simplicity of the example, the real scenario involves more intricate logic that warrants browser-side processing.)
Searching for alternatives or possible oversights regarding the availability of JsonifyObject elsewhere.