
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
next-tsr
sets up an optional typesafe routing system for NextJS. It maintains a global list of both pages and API routes and provides components and functions to easily navigate to pages, or make API requests.
Initialize your NextJS application:
npx next-tsr init
This will generate an @/routes
directory that you can use to navigate to pages and make API requests. It also generates a NEXT-TSR-README.md
file in the root of your project that contains information about how to use the system.
You can update the files when the route paths change using the build
command. This will update the @/routes
directory to reflect the new paths. For example, if you add a new page, you can run the following command to update the routes:
npx next-tsr build
Instead of doing this:
import Link from "next/link";
<Link href={`/product/${product.id}`}>Product</Link>;
You can do this:
import { ProductDetail } from "@/routes";
<ProductDetail.Link productId={product.id}>Product</ProductDetail.Link>;
API routes are fully typesafe. Instead of doing this:
// Data is any
const data = await fetch(`/api/product/${productId}`).then((res) => res.json());
You can do this:
import { getProduct } from "@/routes";
// Data is strongly typed as the response of the getProduct function
const data = await getProduct({ productId });
And both the request and the response are strongly typed.
Because the system knows all of the API routes, their verbs, and their parameters, it can generate an OpenAPI schema for your API. This can be used to generate documentation, or to generate client libraries for your API.
This system is opt-in. You can use it for some routes, and not for others. You can use it for some parts of your application, and not for others. It's designed to be flexible and to work with your existing code, and to be incrementally adoptable.
FAQs
NextJS Typesafe Router
The npm package next-tsr receives a total of 0 weekly downloads. As such, next-tsr popularity was classified as not popular.
We found that next-tsr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.