Skip to content

Make the MetaFunction interface generic #374

@donavon

Description

@donavon

I'm not sure how one is supposed to handle issues like this. I tried to submit a PR, but I don't have permission.

When writing a meta function, it would be nice if data were typed and not just any, like this, for example:

export const meta: MetaFunction<LoaderData> = ({ data }) => {
  return {
    title: 'Public Gists',
    description: `View the latest ${data.length} public gists`,
  };
};

If you changed MetaFunction to be generic and accepte an optional type for data, this would solve the problem as well as maintain backward compatibility.

From e8cf0eaae88d44b1771b1bb9faaa5002eabe6ce9 Mon Sep 17 00:00:00 2001
From: donavon <[email protected]>
Date: Tue, 9 Nov 2021 20:40:40 -0500
Subject: [PATCH] make MetaFunction generic

---
 packages/remix-react/routeModules.ts          | 4 ++--
 packages/remix-server-runtime/routeModules.ts | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/packages/remix-react/routeModules.ts b/packages/remix-react/routeModules.ts
index 4bbd945..7fefc9e 100644
--- a/packages/remix-react/routeModules.ts
+++ b/packages/remix-react/routeModules.ts
@@ -45,9 +45,9 @@ export interface LinksFunction {
  * `<meta>` tags for a route. These tags will be merged with (and take
  * precedence over) tags from parent routes.
  */
-export interface MetaFunction {
+export interface MetaFunction<T = AppData> {
   (args: {
-    data: AppData;
+    data: T;
     parentsData: RouteData;
     params: Params;
     location: Location;
diff --git a/packages/remix-server-runtime/routeModules.ts b/packages/remix-server-runtime/routeModules.ts
index 847261c..5fa5ddd 100644
--- a/packages/remix-server-runtime/routeModules.ts
+++ b/packages/remix-server-runtime/routeModules.ts
@@ -76,9 +76,9 @@ export interface LoaderFunction {
  * `<meta>` tags for a route. These tags will be merged with (and take
  * precedence over) tags from parent routes.
  */
-export interface MetaFunction {
+export interface MetaFunction<T = AppData> {
   (args: {
-    data: AppData;
+    data: T;
     parentsData: RouteData;
     params: Params;
     location: Location;
-- 
2.30.1 (Apple Git-130)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions