explaingit

mattpocock/ts-reset

8,486TypeScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

ts-reset is a tiny TypeScript add-on that fixes three built-in frustrations: JSON.parse returning untyped results.filter(Boolean) not narrowing array types correctly, and type errors when using .includes() on readonly arrays.

Mindmap

mindmap
  root((ts-reset))
    What it fixes
      JSON parse types
      Filter Boolean narrowing
      Readonly includes check
    How it works
      Patches built-in types
      No runtime code
      Like a CSS reset
    Audience
      TypeScript developers
      Frontend engineers
    Setup
      npm install
      Single import
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Make JSON.parse and fetch response parsing return 'unknown' instead of 'any' so TypeScript forces you to check the data

USE CASE 2

Fix .filter(Boolean) so TypeScript correctly understands the resulting array has no null or undefined values

USE CASE 3

Eliminate false TypeScript errors when checking if a value exists in a readonly array using .includes()

Tech stack

TypeScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

ts-reset is a small TypeScript library that fixes several frustrating quirks in TypeScript's built-in type definitions for everyday JavaScript features. TypeScript is a programming language that adds type-checking on top of JavaScript, helping catch mistakes before code runs. However, some of the types that TypeScript ships with for standard JavaScript tools are intentionally loose or produce awkward behavior in practice. The library takes its name from the concept of a CSS reset, a small stylesheet that browser developers use to neutralize inconsistent default styles before writing their own. ts-reset does the same thing for TypeScript: it patches a handful of built-in definitions so they behave more sensibly without you having to write workarounds yourself. The README lists three specific problems it addresses. First, when you fetch data from an API and parse the response as JSON, or when you call JSON.parse directly, TypeScript currently types the result as any, meaning it skips type-checking entirely. ts-reset changes this to unknown, which forces you to check what you actually received before using it. Second, a common JavaScript pattern of filtering an array to remove empty values does not narrow the type correctly in standard TypeScript, but ts-reset makes it work as most developers would expect. Third, checking whether a value is in a readonly array with array.includes often causes a type error, ts-reset widens the check to remove that friction. The README is brief and points to full documentation on the Total TypeScript website for installation instructions and a complete list of changes. The project was created by Matt Pocock, a well-known TypeScript educator.

Copy-paste prompts

Prompt 1
Add ts-reset to my TypeScript project so that JSON.parse always returns 'unknown' instead of 'any' and forces proper type checking
Prompt 2
How do I install ts-reset in a Next.js TypeScript project so that array .filter(Boolean) correctly removes null values from the type?
Prompt 3
Show me a before-and-after example of how ts-reset fixes the TypeScript error I get using .includes() on a readonly string array
Open on GitHub → Explain another repo

← mattpocock on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.