On this page
Overview
Superstruct composes object, array, string, number, and other structs into runtime validators. assert, is, and validate support different error-handling styles, while custom types and coercion extend validation for application-specific data. TypeScript values are narrowed after successful checks.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Compose object, array, and primitive structs into schemas
object, array, string, number, and related helpers define runtime shapes for REST, GraphQL, and other data. Smaller structs can be reused as building blocks for larger models.
Sources: [1]
Choose assert, is, or validate for error handling
assert throws on invalid input, is returns a boolean and acts as a TypeScript type guard, and validate supports result-oriented handling without relying on exceptions.
Sources: [1]
Extend validation with custom types and coercion
define can add application-specific validators such as email or UUID checks, while create and defaulted can coerce data and add defaults before validation.
Sources: [1]
Best fit
Fits frontends and APIs that want small composable runtime validation
It suits projects that prefer JavaScript/TypeScript-native schema definitions in application code rather than depending on an external schema specification.
Sources: [1]
Before adoption
Coercion changes values before validation completes
APIs such as create and other coercion helpers can add defaults or transform input. Keep those flows separate from assert, is, and validate when a boundary is expected to validate without mutation.
Sources: [1]
The v2.0.2 release tag and package manifest have an upstream version mismatch
GitHub's latest release is v2.0.2, while package.json inside that tag still reports 2.0.1. The reviewed main manifest reports 2.0.2. Use the published 2.0.2 package as the adoption baseline rather than relying only on the tag manifest.
Official sources
- [1]Superstruct v2.0.2 README(2026-10-05)
- [2]Superstruct v2.0.2 release(2026-10-05)
- [3]Superstruct package metadata at v2.0.2 tag(2026-10-05)
- [4]Superstruct package metadata at reviewed main commit(2026-10-05)
- [5]Superstruct MIT license(2026-10-05)
Supplemental curator note
Use assert, is, or validate for validation-only flows, and create when defaults or coercion are intended. Separating transformation from pure validation makes API-boundary behavior easier to reason about.
Try it in 3 steps
- 1
Install Superstruct 2.0.2 in an isolated project
Pin the package corresponding to the latest GitHub release.
demo=$(mktemp -d "${TMPDIR:-/tmp}/superstruct.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact superstruct@2.0.2 - 2
Create an object struct and check valid and invalid data
Use the README's
objectandisAPIs and require the correct value to pass while the wrong field type fails.printf "%s\n" "import {is, object, number, string} from 'superstruct';" "const User = object({id: number(), name: string()});" "if (!is({id: 1, name: 'Ada'}, User)) process.exit(1);" "if (is({id: '1', name: 'Ada'}, User)) process.exit(1);" "console.log('validated');" > demo.mjs - 3
Run the validation with Node.js
Confirm the non-throwing
isvalidation flow behaves as expected.node demo.mjs
Growth
Growth trends · Last 30 days
7,127 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 0
- Open PRs
- 22
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- validation
- types
- interface
- structs
- schema
- javascript
- typescript
- Stars
- 7,127
- Forks
- 223
- Watchers
- 43
- Open issues
- 82
- Contributors
- 66
- Owner type
- User
- Primary language
- TypeScript
- License
- MIT
- Repository last updated
- Oct 1, 2024
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- ofetch5,360 Stars
5 shared tag(s) · 1 shared category(s) · Same language
add JSON parsing, retries, timeouts, and interceptors to fetch across Node, browsers, and workers
TypeScript - Ajv14,850 Stars
4 shared tag(s) · 2 shared category(s) · Same language
compile JSON Schema or JTD contracts into fast runtime validators for API and configuration data
TypeScript - openapi-typescript8,391 Stars
4 shared tag(s) · 2 shared category(s) · Same language
generate runtime-free TypeScript types from OpenAPI 3.0 and 3.1 contracts
TypeScript - Typia5,931 Stars
4 shared tag(s) · 2 shared category(s) · Same language
transform TypeScript types into dedicated runtime validators and serializers at build time
TypeScript - Valibot9,027 Stars
4 shared tag(s) · 1 shared category(s) · Same language
combine small functions for runtime schema validation with TypeScript type inference
TypeScript - SWR32,487 Stars
3 shared tag(s) · 2 shared category(s) · Same language
cache remote React data and manage revalidation, deduplication, and updates through hooks
TypeScript
Report incorrect information
Tell us if any listing information is incorrect or outdated.