Skip to content

zoehneto/typewiz

 
 

Repository files navigation

TypeWiz

Automatically discover and add missing types in your TypeScript code.

TypeWiz

Build Status Coverage Status code style: prettier

Introduction

TypeWiz monitors your variable types in runtime, and uses this information to add missing type annotations to your TypeScript code. For instance, given the following source code as input:

function add(a, b) {
    return a + b;
}
add(5, 6);

TypeWiz will automatically detect the types of a and b as number, and will rewrite to code to read:

function add(a: number, b: number) {
    return a + b;
}
add(5, 6);

You can learn more about the project in the blog posts:

Usage

For front-end code, please have a look at the TypeWiz WebPack Plugin.

For node.js code, please check out the typewiz-node Runner.

If you are interested in creating your own custom integration, see the Integration Test for an example how to directly use the TypeWiz API. You can use the API directly by adding this library to your project:

yarn add -D typewiz

or

npm install --save-dev typewiz

Configuration options

TypeWiz functions accepts several configuration options which enable specific features:

  • tsConfig: string (default: undefined) - The path to your project's tsconfig.json file. This is required for several other options, such as when instrumenting implicit this.
  • instrumentCallExpressions: boolean (default: false) - Try to find even more types by combining static analysis with the runtime analysis. TypeWiz will try to use TypeScript's inferred types when determining the type of a function argument. See #27 for an example.
  • instrumentImplicitThis: boolean (default: false) - Find type of this in non-class member functions. See #33 for discussion.
  • prefix: string (default: '') - A prefix to add before each type added by applyTypes(). See #11.

License

Copyright (C) 2018, Uri Shaked. Licensed under the MIT license.

About

Automatically discover and add missing types in your TypeScript code

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 92.7%
  • JavaScript 7.3%