npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@best-skn/next-types

v1.1.1

Published

A Simple Type Definition Extension Library For Next.js 14

Downloads

62

Readme

SKN Next.js Type Extension Library

TypeScript Next.js

NPM Version MIT License

 

Introduction:

This is a simple TypeScript Type Extension Library for Next.js 14

I made this library so that I can use it in all of my Next.js 14 projects without writing the same codes over and over again

 

Details:

ParamProps Type

  • An interface taking a generic that has params property of type Record<T, string>
  • ParamProps is the prop type for Next.js dynamic route page.tsx default exported server component.
  • ParamProps generic type is actually a string which is the name of the slug i.e. the name of the dynamic id
  • The dynamic id can have names like: "slug", "id" etc. which becomes the directory name like: [slug], [id] etc
  • For usage instruction, see Usage section

GenerateMetadata Type

  • GenerateMetadata is the type for Next.js dynamic route generateMetadata function
  • The generic type which is the dynamic id, must match that of ParamProps in a certain dynamic route component
  • For usage instruction, see Usage section

GenerateStaticParams Type

  • GenerateStaticParams is the type for Next.js dynamic route generateStaticParams function
  • The generic type which is the dynamic id, must match that of ParamProps in a certain dynamic route component
  • For usage instruction, see Usage section

NextErrorProps Type

  • an interface for Next.js error.tsx client component
  • NextErrorProps is the prop type for error.tsx default exported function

 

Use Case:

  • Next.js

 

Requirements:

This library has peer dependency for React & React DOM of minimum 18.3.1. It may or may not work on 19.x

This library is intended to be used in Next.js of minimum 14.2.3. It may or may not work on 15.x

 

Complementary Libraries:

 

Usage:

To install the package, type the following in console

npm add -D @best-skn/next-types
#or
yarn add -D @best-skn/next-types
#or
pnpm add -D @best-skn/next-types
#or
bun add -D @best-skn/next-types

Create a directory called types in the root location of your project, and create a file called next.d.ts, then do this

import "@best-skn/next-types";

Check your tsconfig.json, if includes property has **/*.ts & **/*.tsx or not otherwise the type definition file may not work

Now Inside your Next.js 14 Project, use the package like this (Just an example)

ParamProps, GenerateMetadata & GenerateStaticParams Types:

For any dynamic routes, use like this

// Location: app/users/[slug]/page.tsx
// Dynamic id: slug
import type {
  GenerateMetadata,
  GenerateStaticParams,
  ParamProps,
} from "next";

// Generic type here `slug` as the dynamic id is that
export const generateMetadata: GenerateMetadata<"slug"> = async (props) => {
  const { slug } = props.params;
  // some codes here...
  return {
    // some codes here...
  };
};

// Generic type here `slug` as the dynamic id is that
export const generateStaticParams: GenerateStaticParams<"slug"> = async () => {
  // your code for generating static params here...
  // you'll get type safe dynamic route: `slug`
};

// Generic type here `slug` as the dynamic id is that
// here `React.SC` type is from my another package: `@best-skn/react-types`
const User: React.SC<ParamProps<"slug">> = async (props) => {
  const { slug } = props.params; // you'll get a type safe dynamic id name

  return ();
};

NextErrorProps Type:

For error.tsx files, use like this

"use client";

import type { NextErrorProps } from "next";

const Error: React.FC<NextErrorProps> = (props) => {
  const { error, reset } = props;
  // some codes here...
  return (
    <div>something...</div>
  );
};

 

Dedicated To:

  • 👩‍⚕️Tanjila Hasan Trina: The long lost love of my life. The course of nature separated us from our paths and put us in separate places far away from each other. But no matter how separated we are right now, each and every moment of mine is only dedicated to you. We may not see each other in this lifetime as it seems but I will find you again in the next life. I just want to say: 世界は残酷だ それでも君を愛すよ
  • 💯My Parents: The greatest treasures of my life ever.

 

License:

Copyright (C) 2024 SKN Shukhan

Licensed under the MIT License