@ergodark/next-types
This package contains various utility and helper types that can be imported by a
Next.js project.
This package only contains TypeScript types. This package also exports all the
types from @ergodark/types, so
there is no need to install both packages.
Install
npm install @ergodark/next-types
Usage
You can use this library's types in your TypeScript projects like so:
import type { TypeNameHere } from '@ergodark/next-types'
const variable: TypeNameHere;
import type * as ErgoDark from '@ergodark/next-types'
const variable: ErgoDark.TypeNameHere;
Type Glossary
Along with the types exposed by
@ergodark/types,
this library provides the following types:
NextParamsRR<T>
Represents an object with well-defined NextApiRequest and NextApiResponse
properties where generic type T
is passed to
NextApiResponse<T>.
Specifying T
is optional. By default, T = Record<string, unknown>
.
import type { NextParamsRR } from '@ergodark/next-types'
export async function addToRequestLog({ req, res }: NextParamsRR) {
...
}
WithConfig<T>
Adds a config
property to type T
. Useful for dealing with Next endpoints
that require custom
configuration
when writing unit tests.
import * as Endpoint from 'pages/api-endpoint'
import type { WithConfig } from '@ergodark/next-types'
const endpoint: WithConfig<typeof Endpoint.default> = Endpoint.default;
endpoint.config = Endpoint.config;
Contributing
Issues and pull requests are welcome! In lieu of a formal styleguide, take care
to maintain the existing coding style.
Please test your code!
Release History