• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Compile TypeScript interfaces into a description that allows runtime validation

ts-interface-builder

Build Status npm version

Compile TypeScript interfaces into a description that allows runtime validation.

This tool runs at build time to create runtime validators from TypeScript interfaces. It allows validating data, such as parsed JSON objects received over the network, or parsed JSON or YAML files, to check if they satisfy a TypeScript interface, and to produce informative error messages if they do not.

Installation

npm install --save-dev ts-interface-builder
npm install --save ts-interface-checker

Usage

This module works together with ts-interface-checker module. You use ts-interface-builder in a build step that converts some TypeScript interfaces to a new TypeScript or JavaScript file (with -ti.ts or -ti.js extension) that provides a runtime description of the interface. You then use ts-interface-checker in your program to create validator functions from this runtime description.

`npm bin`/ts-interface-builder [options] <typescript-files...>

By default, produces <ts-file>-ti.ts file for each input file, which has runtime definitions for all types in the input file. For example, if you have a TypeScript file that defines some types:

// foo.ts
interface Square {
  size: number;
  color?: string;
}

Then you can generate code for runtime checks with:

`npm bin`/ts-interface-builder foo.ts

It produces a file like this:

// foo-ti.ts
import * as t from "ts-interface-checker";

export const Square = t.iface([], {
  "size": "number",
  "color": t.opt("string"),
});

const exportedTypeSuite: t.ITypeSuite = {
  Square,
};
export default exportedTypeSuite;

See ts-interface-checker module for how to use this file in your program.

Limitations

This module currently does not support generics, except Promises. Promises are supported by unwrapping Promise<T> to simply T.

More Repositories

1

grist-core

Grist is the evolution of spreadsheets.
TypeScript
6,985
star
2

ts-interface-checker

Runtime library to validate data against TypeScript interfaces.
TypeScript
323
star
3

asttokens

Annotate Python AST trees with source text and token information
Python
172
star
4

grist-desktop

Desktop Grist, packaged with Electron
TypeScript
166
star
5

mkdocs-windmill

Outstanding mkdocs theme with a focus on navigation and usability
CSS
105
star
6

grist-static

Showing Grist spreadsheets on a static website, without a special backend.
TypeScript
88
star
7

grist-widget

A repository of custom widgets to embed in Grist documents
JavaScript
56
star
8

grist-omnibus

an opinionated Grist+Dex+Traefik package for first-time self-hosters
JavaScript
52
star
9

yaml-cfn

Parser and schema for CloudFormation YAML templates
JavaScript
31
star
10

py_grist_api

Python client for interacting with Grist
Python
19
star
11

grist-help

Grist documentation and help center articles
HTML
13
star
12

grist-api

NodeJS client for interacting with Grist
TypeScript
13
star
13

grainjs

Javascript library from Grist Labs
TypeScript
13
star
14

grist-ee

The source code for self-managed Grist Enterprise.
TypeScript
11
star
15

aws-lambda-upload

Package and upload an AWS lambda with its minimal dependencies
JavaScript
7
star
16

secrets.js

Tiny node tool to share secrets using public key crypto
JavaScript
6
star
17

jupyterlite-widget

Python
3
star
18

grain-rpc

Typed RPC interface on top of an arbitrary communication channel
TypeScript
3
star
19

grist-pug-py-widget

Grist widget to directly develop custom widgets within Grist’s UI.
JavaScript
3
star
20

grist-form-submit

Turn form submissions on webpages into new records in Grist documents
TypeScript
3
star
21

mocha-webdriver

Write Mocha style tests using selenium-webdriver, with many conveniences.
TypeScript
3
star
22

npm-check-shrinkwrap

Quickly check if contents of node_modules correspond to npm-shrinkwrap.json
JavaScript
2
star
23

grist-plugin-examples

2
star
24

collect-js-deps

Collect the minimal list of dependencies required by a JS file.
JavaScript
1
star
25

grist-zapier

Code behind the initial Grist/Zapier integration, exported as a reference.
JavaScript
1
star