ethanniser / next-typesafe-url

Fully typesafe, JSON serializable, and zod validated URL search params, dynamic route params, and routing for NextJS.
https://next-typesafe-url.dev
MIT License
362 stars 16 forks source link

fix: update `SomeReactComponent` type #98

Closed risk1996 closed 3 months ago

risk1996 commented 3 months ago

Description

This PR updates the SomeReactComponent type to include all of the things that are accepted in a React.FunctionComponent (or React.FC) type.

Before

Currently, if someone were to use the withParamValidation or withLayoutParamValidation HOC on a React component manually annotated with React.FC, such as:

import type React from "react";
import { withParamValidation, type InferPagePropsType } from "next-typesafe-url";

import { route } from "./routeType";

const SomePage: React.FC<InferPagePropsType<typeof route>> = () => null;

export default withParamValidation(SomePage, route);

TypeScript will throw an error.

Argument of type 'FunctionComponent<InferPagePropsType<{ ... }>> & { ...; }' is not assignable to parameter of type 'SomeReactComponent'.
  Type 'ReactNode' is not assignable to type 'Element | Promise<Element>'.
    Type 'undefined' is not assignable to type 'Element | Promise<Element>'.ts(2345)

After

TypeScript will no longer show the previous error.

ethanniser commented 3 months ago

thank you for your contribution