Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
/ tsguard.macro Public archive

Babel macro that automatically generates type guards for a given type (WIP)

Notifications You must be signed in to change notification settings

vhfmag/tsguard.macro

Repository files navigation

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.

NPM

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;
}

About

Babel macro that automatically generates type guards for a given type (WIP)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published