Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,17 @@ interface Square {
}
```

The first step is to generate some code for runtime checks:
```bash
`npm bin`/ts-interface-builder foo.ts
```
The first step is to obtain a [type suite](#type-suites) (runtime type definitions) for the TypeScript file.

It produces a file like this:
```typescript
// foo-ti.js
import * as t from "ts-interface-checker";

export const Square = t.iface([], {
"size": "number",
"color": t.opt("string"),
});
...
```
`ts-interface-builder` offers two ways to do this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your other message explaining this change.

I'd like to keep the example here. You are right that it's redundant along with ts-interface-builder's documentation, but the version here is sufficient for a good number of readers, who don't have to get into further details.

How about after this paragraph, adding ### Option 1: Using the CLI with the body as before (including the command line, the example of a generated file, and how to import it), and then ### Option 2: Using the Babel macro with the body containing a link to the details, as well as a snippet of code like

import { getCheckers } from "ts-interface-builder/macro";
const {Square} = createCheckers('./foo.ts');
Square.check({size: 1}); 

ts-interface-checker is the more popular repo, so I think it's good if its README is sufficient to get people to something working.

1. use the [CLI](https://github.com/gristlabs/ts-interface-builder#cli)
to generate a module (.ts or .js file) that exports the type suite
2. use the [babel macro](https://github.com/gristlabs/ts-interface-builder#babel-macro)
to generate the type suite as part of your babel build step

Now at runtime, to check if a value satisfies the Square interface:
Once you have a type suite for `foo.ts` (let's call it `fooTI`),
you can check if a value satisfies the `Square` interface like so:
```typescript
import fooTI from "./foo-ti";
import {createCheckers} from "ts-interface-checker";

const {Square} = createCheckers(fooTI);
Expand Down