Giter Site home page Giter Site logo

sfast / typewiz Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mockdeep/typewiz

0.0 2.0 0.0 539 KB

Automatically discover and add missing types in your TypeScript code

Home Page: https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c

TypeScript 97.51% JavaScript 2.49%

typewiz's Introduction

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.

To use TypeWiz from the command line try the TypeWiz CLI.

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-core

or

npm install --save-dev typewiz-core

Configuration options

Configuration options can be specified using the typewiz.json configuration file. This file is used by typewiz-node and typewiz-webpack and can be parsed using the ConfigurationParser class in typewiz-core for custom integrations.

The typewiz.json file has the following format:

{
    "common":{
        "rootDir":".",
        "tsConfig":"tsconfig.json"
    },
    "instrument":{
        "instrumentCallExpressions":true,
        "instrumentImplicitThis":true,
        "skipTwizDeclarations":true
    },
    "applyTypes":{
        "prefix":"TypeWiz |"
    }
}

Options:

  • rootDir: string (default: undefined) - If given, all the file paths in the collected type info will be resolved relative to this directory.

  • tsConfig: string (default: undefined) - The path to your project's tsconfig.json file. This is required for several other options, like instrumenting implicit this and type inference using static analysis.

  • 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.

  • skipTwizDeclarations: boolean (default: false) - Don't add a declaration of $_$twiz to instrumented files.

  • 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.

typewiz's People

Contributors

urish avatar zoehneto avatar madarauchiha avatar kaminskypavel avatar guywarburg avatar kamal avatar ycheapopo avatar

Watchers

James Cloos avatar Shushanik Tovmasyan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.