
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
yup-type-support
Advanced tools
A typescript support for yup. Able to infer the yup schema from a typescript interface.
A typescript compiler plugin that infers yup schema object from a typescript type or interface.
Use the package manager npm to install Yup Type Support.
npm i yup-type-support -D
Yup Type Support requires ttypescript. You can install the ttypescript using:
npm i ttypescript -D
Next you need to edit the tsconfig file to add the plugin to the compiler options.
{
"compilerOptions": {
"plugins": [{ "transform": "yup-type-support", "type": "program" }],
}
}
To use the yup type support to generate yup schema object at the compile time automatically, you simply need to put a comment annotation in the yup.object() function call.
Example:
import * as yup from 'yup'
export interface simpleAccount {
id: number;
name: string;
checking: boolean;
notes?: string;
}
/* this will generate the following schema at compile time
* exports.simpleAccountSchema = yup.object({
* id: yup.number().required(),
* name: yup.string().required(),
* checking: yup.boolean().required(),
* note: yup.string().optional()
* });
*/
export const simpleAccountSchema: yup.SchemaOf<simpleAccount> = yup.object(/* guess schema */);
Currently, the plugin only supports number and string type, as well as the optional mark. More features are still under development. You also need to follow the format in the example closely (mainly how you declare the schema that will get changed in compile time), more flexible format support is also under development.
Now you can compile your typescript file using (or you can add the command to your package.json file):
ttsc
Currently, the yup-type-support supports all three primitive types in typescript. Support for array, enum and other types are still under development.
interface myInterface {
key: string
}
// The interface above generates the following schema
const myInterfaceSchema: yup.SchemaOf<myInterface> = yup.object({
key: yup.string().required(),
});
interface myInterface {
key: number
}
// The interface above generates the following schema
const myInterfaceSchema: yup.SchemaOf<myInterface> = yup.object({
key: yup.number().required(),
});
interface myInterface {
key: boolean
}
// The interface above generates the following schema
const myInterfaceSchema: yup.SchemaOf<myInterface> = yup.object({
key: yup.boolean().required(),
});
Currently, the yup-type-support supports requried and optional property of yup. Support for nullable is still under development.
interface myInterface {
key?: string
}
// The interface above generates the following schema
const myInterfaceSchema: yup.SchemaOf<myInterface> = yup.object({
key: yup.string().optional(),
});
The development for now will focus on supporting more types, including array, enum, etc. For properties, nullable will be supported soon. The next major goal is to support nested types and convert them to the nested schema for yup.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
FAQs
A typescript support for yup. Able to infer the yup schema from a typescript interface.
The npm package yup-type-support receives a total of 10 weekly downloads. As such, yup-type-support popularity was classified as not popular.
We found that yup-type-support demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.