tsguard.macro
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

tsguard.macro - Typescript type guard macro

Babel macro that automatically generates type guards for a given type (very much WIP). You'll need to install generic-type-guards for this to work.

Roadmap

  • Implement tests
  • Support type references (e.g. typeGuard<IProps>)
  • Support tuples
  • Support mapped types
  • Support rest operator
  • Support index accessed types

Usage

import typeGuard from "tsguard.macro";
 
const unsafeValue = await fetch(someUrl).then(res => res.json());
 
if (typeGuard<{ name: string; value?: number }>(unsafeValue)) {
  const safeValue: { name: string; value?: number } = unsafeValue;
}

Package Sidebar

Install

npm i tsguard.macro

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

198 kB

Total Files

11

Last publish

Collaborators

  • vhfmag