Skip to content

types/_generator-typings

Repository files navigation

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

  • Basic scaffolding
  • Source delivery mechanisms
    • npm
    • bower
    • github
    • jspm
  • Source hostings providers
    • github
    • bitbucket
    • gitlab
    • custom
  • Install target source automatically
  • Add source as submodule
  • Install supporting utilities and settings
  • Test harness
    • Server side
    • Client side
      • blue-tape (through tape-run)
      • mocha (through mocha-phantomjs, karma-mocha)
      • jasmine
      • QUnit
  • npm commands
    • watch: Build typings for testing automatically
    • publish: Create PR to typings/registry
    • individual commands
      • build: Build typings for testing
      • lint: Run tslint
      • test: Run tests
      • source-test: Run tests transferred from source

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