Registry / devops / joi2types

joi2types

JSON →
library1.1.1jsnpmunverified

Converts @hapi/joi schemas into TypeScript types. Current version 1.1.1, stable with weekly updates. Outputs TypeScript interfaces/types from Joi schema definitions, supporting banner comments, custom interface names, and unknown property handling. Differentiator: eliminates manual translation of Joi validation schemas to TypeScript types, reducing duplication and errors. Requires @hapi/joi 16.x as a peer dependency. Not maintained actively (last update 2019).

npm install joi2types
INSTALL
IMPORT
SIG · JOI2TYPES
J
joi2types
devopsjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import joi2Types from 'joi2types'
Default export is a function; TypeScript users should prefer ESM import.
default
const joi2Types = require('joi2types').default
const joi2Types = require('joi2types')
CommonJS require must use .default because the library uses ESM export default.
Joi
import Joi from '@hapi/joi'
Joi is not from joi2types; it's a separate peer dependency needed to define schemas.

Demonstrates converting a Joi schema for route configuration into a TypeScript type using a custom interface name.

import Joi from '@hapi/joi'; import joi2Types from 'joi2types'; const schema = Joi.array().items( Joi.object({ path: Joi.string().description('Any valid URL path'), component: Joi.string().description('A React component to render only when the location matches.'), redirect: Joi.string().description('navigate to a new location'), exact: Joi.boolean().description('When true, the active class/style will only be applied if the location is matched exactly.') }).unknown() ); (async () => { const types = await joi2Types(schema, { bannerComment: '/** comment for test */', interfaceName: 'IRoute' }); console.log(types); })();
Debug
Known issues
gotchaLibrary uses @hapi/joi 16.x, not the newer 'joi' package (v17+). Mixing versions will cause runtime errors.
fix
Install @hapi/joi@16 with 'npm install @hapi/joi@16'
affects: >=1.0
deprecatedThe functions joi2Types expects a Joi schema object, but does not validate the input; passing an error-first schema or invalid object silently fails or returns empty string.
fix
Ensure the schema is created with Joi methods (e.g., Joi.object()) before passing to joi2Types
affects: >=1.0
gotchaCommonJS require must use .default; direct require('joi2types') returns an object with a default property.
fix
Use require('joi2types').default or switch to ESM import
affects: >=1.0
breakingThe function returns a Promise; forgetting to await or not handling async will result in undefined.
fix
Await the call: const types = await joi2Types(schema);
affects: >=1.0
Errors
Common errors & fixes
TypeError: joi2Types is not a function
Using require('joi2types') instead of require('joi2types').default in CommonJS
fix
Change to const joi2Types = require('joi2types').default;
Error: Cannot find module '@hapi/joi'
@hapi/joi is a peer dependency not installed
fix
Install @hapi/joi@16 with npm install @hapi/joi@16
UnhandledPromiseRejectionWarning: TypeError: schema.validate is not a function
Passing a plain object instead of a Joi schema
fix
Create schema using Joi methods (e.g., Joi.object({...}))
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@hapi/joirequiredPeer dependency: converts Joi schemas, must be installed alongside
Agent activity
9 hits · last 30 days
node
8
Resources
joi2types — npm install joi2types · libregistry