Home

Awesome

generator-typings

NPM version downloads Dependency Status Build Status Appveyor status License

Yeoman generator for typings (next-gen of tsd/DefinitelyTyped) project

Upgrade from previous version? Make sure you check the upgrade doc

Features

Installation

First, install Yeoman and generator-typings using npm.

npm install -g yo
npm install -g generator-typings

Usage

There are several ways to create your typings repository:

Here are examples to create npm-noop2

# create the github repo from github website
# under your organization folder (e.g. /somewhere/typed-typings/)
yo typings npm-noop2

# Once it is done,
cd npm-noop2
# create the github repo from github website
# clone it locally to your machine (e.g. into /somewhere/typed-typings/npm-noop2/)
# in that directory:
yo typings
# create the github repo from github website
# under your organization folder (e.g. /somewhere/typed-typings/)
mkdir npm-noop2 && cd npm-noop2
yo typings

How to write typings

About writing tests for typings

Simply shape test (like those in DefinitelyTyped) is not sufficient. Since there is no type in javascript, even if you create a wrong signature, you won't detect it until runtime.

e.g.

// source code
function foo(something) {
  return something++;
}

The source code expects something to be a number. If you write your typings as:

function foo(something: string): string;

It won't fail until you use it. i.e.

// consumer program
import foo ....somehow

let x = "abc";
foo(x);

Because your typings provide guidance to the consumer, they will write their code that way and will fail when they run it. tsc will compile fine.

License

MIT © unional