{"id":49465,"library":"suretype","title":"suretype","description":"Suretype is a ridiculously fast and type-safe JSON schema validator for TypeScript and JavaScript. Current stable version is 3.3.1 (pure ESM, Node >=14.13.1 or >=16.0.0). It compiles validator functions using Ajv, extracts JSON Schema, and deduces TypeScript types at compile-time. Key differentiators: ~70x faster than Joi, ~100x faster than Superstruct, ~2500x faster than Zod; supports full JSON Schema but nothing beyond; errors prettified with awesome-ajv-errors; integrates with typeconv for conversion to/from JSON Schema, Open API, TypeScript types, or GraphQL. Works in browsers.","status":"active","version":"3.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/grantila/suretype","tags":["javascript","typesafe","validate","validator","json","schema","typescript"],"install":[{"cmd":"npm install suretype","lang":"bash","label":"npm"},{"cmd":"yarn add suretype","lang":"bash","label":"yarn"},{"cmd":"pnpm add suretype","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for fast validation compilation","package":"ajv","optional":false}],"imports":[{"note":"ESM-only since v3; cannot require() from CommonJS.","wrong":"const { v } = require('suretype')","symbol":"v","correct":"import { v } from 'suretype'"},{"note":"TypeOf is a type-only export; use 'import type' for TypeScript.","wrong":"import { TypeOf } from 'suretype'","symbol":"TypeOf","correct":"import type { TypeOf } from 'suretype'"},{"note":"compile is a named export, not default.","wrong":"import compile from 'suretype'","symbol":"compile","correct":"import { compile } from 'suretype'"}],"quickstart":{"code":"import { v, compile } from 'suretype';\n\nconst userSchema = v.object({\n  firstName: v.string().required(),\n  lastName: v.string(),\n  age: v.number().gte(21),\n});\n\ntype User = TypeOf<typeof userSchema>;\n// User is: { firstName: string; lastName?: string; age?: number; }\n\nconst validate = compile(userSchema);\n\nconst data = { firstName: 'Alice', age: 30 };\nconst result = validate(data);\nif (result.valid) {\n  console.log('Valid user:', result.data);\n} else {\n  console.error('Validation errors:', result.errors);\n}","lang":"typescript","description":"Defines a user schema, compiles a validator, validates data, and logs result."},"warnings":[{"fix":"Use ES modules (\"type\": \"module\" in package.json) or dynamic import().","message":"Version 3 is pure ESM; cannot be imported with require() from CommonJS.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade Node.js to ^14.13.1 || >=16.0.0.","message":"Node.js <14.13.1 is not supported; common patterns like require('suretype') will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Avoid mutating 'v' directly; create local schemas instead.","message":"The 'v' object is a singleton; modifying it globally may affect other validators.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use Ajv's custom keyword extension if needed, but it's not directly exposed by suretype.","message":"Unlike Joi or Zod, suretype only supports JSON Schema features; you cannot use custom validation logic like .custom() or .refine().","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'100x':52 '14.13.1':26 '16.0.0':28 '2500x':56 '3.3.1':22 '70x':48 'ajv':34,72 'api':83 'awesom':71 'awesome-ajv-error':70 'beyond':66 'browser':90 'compil':30,44 'compile-tim':43 'convers':78 'current':18 'deduc':39 'differenti':47 'error':67,73 'esm':24 'extract':35 'fast':6 'faster':49,53,57 'full':61 'function':32 'graphql':87 'integr':74 'javascript':17,91 'joi':51 'json':11,36,62,80,95 'key':46 'node':25 'noth':65 'open':82 'prettifi':68 'pure':23 'ridicul':5 'safe':10 'schema':12,37,63,81,96 'stabl':19 'superstruct':55 'support':60 'suretyp':1,2 'time':45 'to/from':79 'type':9,41,85 'type-saf':8 'typeconv':76 'typesaf':92 'typescript':15,40,84,97 'use':33 'valid':13,31,93,94 'version':20 'work':88 'zod':59","created_at":"2026-06-07T17:01:55.098510+00:00","updated_at":"2026-06-07T17:01:55.098510+00:00","problems":[{"fix":"Add \"type\": \"module\" to package.json or rename file to .mjs.","cause":"Using ESM import in a CommonJS project without proper configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use dynamic import: const { v } = await import('suretype'); or switch to ES modules.","cause":"Trying to require('suretype') in a CommonJS module.","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Ensure you have the correct named import: import { v } from 'suretype';","cause":"Importing 'v' incorrectly (e.g., default import or destructuring from wrong path).","error":"TypeError: v.object is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/grantila/suretype#readme","github":"https://github.com/grantila/suretype","docs":null,"changelog":null,"pypi":null,"npm":"suretype","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}