Is it possible to have data parameter typed in meta function export?
shripadk opened this issue · 1 comments
shripadk commented
Firstly, thank you for the awesome library and for bringing end-to-end type safety to Remix.
I have a problem that is specific to the exported meta
function from a route.
Have a posts/$slug
route which has a loader
which exports few posts and rendered markdown in html format. With remix-typedjson
it looks something like this:
export const loader = async ({ params }: LoaderArgs) => {
invariant(params.slug, "params.slug is required")
const post = await getPost(params.slug)
invariant(post, `Post not found: ${params.slug}`)
const html = marked(post.markdown)
return typedjson({
post,
html,
})
}
But when I want to access the returned data in the meta
function to add a title for my page, I obviously don't get the types as MetaFunction
by default has data
set to any
:
export const meta: MetaFunction = ({ data }) => {
console.log("Data:", data)
return {
title: `Posts | ${data.post.title}`,
}
}
Is it possible to type data
returned from loader
in the meta
function?
kiliman commented
Thanks. I’ll see about adding a meta export as well.