{"id":49292,"library":"schema-typed","title":"schema-typed","description":"schema-typed is a data modeling and validation library for JavaScript and TypeScript, now at v2.4.2 (stable). It provides a fluent API to define schemas with typed validators (StringType, NumberType, ArrayType, ObjectType, BooleanType, DateType) and supports synchronous and asynchronous validation, nested object validation, field dependencies, custom rules, and schema composition via SchemaModel.combine(). Key differentiators: strong TypeScript support with full type inference for validated data, a builder pattern for readable schemas, and detailed error messages. It is maintained and widely used in the rsuite ecosystem but can be used standalone.","status":"active","version":"2.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/rsuite/schema-typed","tags":["javascript","schema","validation","typescript"],"install":[{"cmd":"npm install schema-typed","lang":"bash","label":"npm"},{"cmd":"yarn add schema-typed","lang":"bash","label":"yarn"},{"cmd":"pnpm add schema-typed","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is the standard. The package also supports CommonJS via default export, but named imports are preferred for TypeScript.","wrong":"const SchemaModel = require('schema-typed').SchemaModel","symbol":"SchemaModel","correct":"import { SchemaModel } from 'schema-typed'"},{"note":"All type factories are named exports from the main entry. Do not import from subpaths.","wrong":"import { StringType } from 'schema-typed/StringType'","symbol":"StringType","correct":"import { StringType } from 'schema-typed'"},{"note":"NumberType is a named export, not a default export. Use destructuring.","wrong":"import NumberType from 'schema-typed'","symbol":"NumberType","correct":"import { NumberType } from 'schema-typed'"}],"quickstart":{"code":"import { SchemaModel, StringType, NumberType } from 'schema-typed';\n\nconst userModel = SchemaModel({\n  username: StringType().isRequired('Username is required').minLength(3, 'Must be at least 3 characters'),\n  age: NumberType().isRequired('Age is required').range(0, 150, 'Age must be between 0 and 150')\n});\n\nconst data = { username: 'al', age: 200 };\nconst checkResult = userModel.check(data);\nconsole.log(checkResult);\n// => { username: { hasError: false }, age: { hasError: true, errorMessage: 'Age must be between 0 and 150' } }","lang":"typescript","description":"Creates a user schema with required string and number fields, then validates sample data showing error messages."},"warnings":[{"fix":"Use `isRequiredOrEmpty(errorMessage)` instead of `isRequired` if you want to allow empty but still validate other rules.","message":"The `isRequired` method trims whitespace by default. If you need to allow empty strings, use `isRequiredOrEmpty`.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a custom rule with `addRule` for nested field comparisons.","message":"When using `equalTo`, the field name must match exactly the key in the data object. It does not support nested paths.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check all fields: `Object.values(result).every(f => !f.hasError)`.","message":"`check` and `checkAsync` return an object keyed by field names, each with `hasError` and `errorMessage`. If all pass, `hasError` is `false` for each field. There is no top-level `isValid` flag.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use `when` sparingly and consider caching schemas if needed.","message":"The `when` method conditionally changes the type based on other fields. But it creates a new type instance each time, which may cause performance issues if re-evaluated often.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use `StringType().pattern(...)` on a stringified version of the number.","message":"`pattern` only exists on StringType, not on other types. For regex on numbers, convert to string first.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'api':26 'arraytyp':35 'asynchron':43 'booleantyp':37 'builder':70 'composit':54 'custom':50 'data':9,68 'datetyp':38 'defin':28 'depend':49 'detail':76 'differenti':58 'ecosystem':88 'error':77 'field':48 'fluent':25 'full':63 'infer':65 'javascript':15,94 'key':57 'librari':13 'maintain':81 'messag':78 'model':10 'nest':45 'numbertyp':34 'object':46 'objecttyp':36 'pattern':71 'provid':23 'readabl':73 'rsuit':87 'rule':51 'schema':2,5,29,53,74,95 'schema-typ':1,4 'schemamodel.combine':56 'stabl':21 'standalon':93 'stringtyp':33 'strong':59 'support':40,61 'synchron':41 'type':3,6,31,64 'typescript':17,60,97 'use':84,92 'v2.4.2':20 'valid':12,32,44,47,67,96 'via':55 'wide':83","created_at":"2026-06-07T17:01:01.258598+00:00","updated_at":"2026-06-07T17:01:01.258598+00:00","problems":[{"fix":"Use `const model = SchemaModel({...})` without `new`.","cause":"Using `new SchemaModel(...)` instead of calling it as a function.","error":"TypeError: SchemaModel is not a constructor"},{"fix":"Ensure the field exists in the schema and data. Use optional chaining: `result.fieldName?.hasError`.","cause":"Accessing `result.fieldName` where `fieldName` was not validated because it wasn't in the schema or data.","error":"Cannot read properties of undefined (reading 'hasError')"},{"fix":"Parse input to number before validation: `age: NumberType().isInteger('Must be integer').check(Number(value))`.","cause":"Data from form inputs are strings by default, but NumberType expects numeric values.","error":"Type 'string' is not assignable to type 'number' in NumberType().isInteger()"}],"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/rsuite/schema-typed#readme","github":"https://github.com/rsuite/schema-typed","docs":null,"changelog":null,"pypi":null,"npm":"schema-typed","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}}