Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-interface-checker

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-interface-checker

Runtime library to validate data against TypeScript interfaces

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11M
increased by5.16%
Maintainers
2
Weekly downloads
 
Created

What is ts-interface-checker?

The ts-interface-checker package is used to perform runtime type checking of objects against TypeScript interfaces. It works by using a companion compiler that generates runtime type information, which can then be used to validate objects at runtime, ensuring they conform to the specified TypeScript interfaces.

What are ts-interface-checker's main functionalities?

Type Checking

This feature allows you to check if an object matches a TypeScript interface. The example shows how to import the checkers, load the generated type information, and use the checker to validate an object.

const { createCheckers } = require('ts-interface-checker');
const ti = require('./type-info');

const { UserChecker } = createCheckers(ti);

const user = { name: 'Alice', age: 25 };
UserChecker.check(user);

Custom Error Reporting

This feature allows you to catch and report errors when an object fails to match the interface. The example demonstrates how to use a try-catch block to handle validation errors and output a custom error message.

const { createCheckers } = require('ts-interface-checker');
const ti = require('./type-info');

const { UserChecker } = createCheckers(ti);

try {
  const user = { name: 'Alice', age: '25' };
  UserChecker.check(user);
} catch (error) {
  console.error('Validation failed:', error.message);
}

Partial Checking

This feature enables checking for partial conformance to an interface, useful when only a subset of properties is required. The example shows how to check a partial object against a TypeScript interface.

const { createCheckers } = require('ts-interface-checker');
const ti = require('./type-info');

const { UserChecker } = createCheckers(ti);

const partialUser = { name: 'Bob' };
UserChecker.strictCheck(partialUser, 'Partial<User>');

Other packages similar to ts-interface-checker

Keywords

FAQs

Package last updated on 11 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc