Skip to content

ITBoomDev/next-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@itboom/next-types 🚀

@itboom/next-types is a global TypeScript utility that provides strongly-typed, collision-safe prop types for Next.js App Router components.

It includes three globally available types — NextPageProps, NextLayoutProps, and NextRouteProps — optimized for use in asynchronous environments where params and searchParams are promises.


Table of Contents

  1. Features ✨
  2. Installation 📦
  3. Usage 🔧
  4. Examples
  5. API Reference 📚
  6. License 📄
  7. Contributing 🤝
  8. Author 👤

Features ✨

  • Two usage modes: Import types or enable them globally via tsconfig.json
  • 🧠 Async-first design: All props are promise-wrapped for await support
  • 🧩 Collision-safe names: No clashes with LayoutProps from other libraries
  • 🔍 Clear intent: Names follow NextPageProps, NextLayoutProps, NextRouteProps
  • Lightweight: Types only, zero runtime code

Installation 📦

Bun

bun add @itboom/next-types

npm

npm install @itboom/next-types

Usage 🔧

Option 1: Import types

import type {
  NextPageProps,
  NextLayoutProps,
  NextRouteProps
} from '@itboom/next-types';

Option 2: Enable global types

In your tsconfig.json:

{
  "compilerOptions": {
    "types": ["@itboom/next-types"]
  }
}

If IntelliSense doesn’t work immediately, reload VS Code or restart the TS server.


Examples

Page Props

// /app/product/[id]/page.tsx

const Page = async (
  { params, searchParams }: NextPageProps<{ id: string }, { lang: string }>
) => {
  const { id } = await params;
  const { lang } = await searchParams;

  return <div>Product ID: {id} | Language: {lang}</div>;
};

Layout Props

// /app/[locale]/layout.tsx

const Layout = async (
  { children, params }: NextLayoutProps<{ locale: string }>
) => {
  const { locale } = await params;

  return (
    <html lang={locale}>
      <body>{children}</body>
    </html>
  );
};

Route Props

// /app/api/user/[id]/route.ts

const GET = async ({ params }: NextRouteProps<{ id: string }>) => {
  const { id } = await params;

  return new Response(`User ID: ${id}`);
};

API Reference 📚

NextPageProps<Params, SearchParams>

Props type for page.tsx components:

  • params: Promise<Params> – dynamic route segments
  • searchParams: Promise<SearchParams> – parsed query string

NextLayoutProps<Params>

Props type for layout.tsx components:

  • params: Promise<Params>
  • children: React.ReactNode

NextRouteProps<Params>

Props type for route.ts handlers:

  • params: Promise<Params>

License 📄

MIT License. See the LICENSE file for details.


Contributing 🤝

Issues, ideas, and PRs are welcome — help improve typing hygiene for the Next.js ecosystem!


Author 👤

Created by Bohdan Kulinchenko
Founder of itboom.dev
GitHub: @ITBoomDev


Enjoy using @itboom/next-types — and type your props the clean and correct way. 🔥

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published