Code Monkey home page Code Monkey logo

mono-ts-check's Introduction

Providing a progressive way to execute a TypeScript check.

Why?

Many people use tsc with lint-staged to execute a TypeScript check during the commit stage. It works well in most cases.

But consider the following situation:

// a.ts
export const obj = {}
console.log(obj.foo)  // foo does not exist on obj
// b.ts
import { obj } from './a'

If you run tsc on b.ts, it will appear that b.ts contains no TypeScript errors. However, you won’t pass the TypeScript check because another error occurred in a.ts.

Your project may contain a large number of errors. In this case, it may be impossible to fix all of them during a single commit. Or put another way, you only care about the errors in specific files and want to ignore all other potential errors in other files.

This tool provides a gentler way to solve this problem.

Instead of using tsc, this tool only outputs errors based on the files you provide.

So here, if you run mono-ts-check on b.ts, you won’t get any errors.

Setup

ONLY TESTED ON TYPESCRIPT 5

  • Install lint-staged, follow the instructions.

  • To install, use:

    npm i -D @hong97/mono-ts-check
  • In package.json, add mono-ts-check to *.ts, *.tsx files.

    "lint-staged": {
      "*.{ts,tsx}": [
        "mono-ts-check"
      ]
    },
  • Use Husky or other methods to set up your git 'pre-commit' hooks.

  • Now, TypeScript will be checked at commit staged.

Configuration

Create a file named monoTsCheckConfig.js in your root directory:

module.exports = {
  alwaysInclude: [
    // always included in tsc process no matter these files are staged or not
  ],
  ignore: [
    // use glob pattern, see more: https://www.npmjs.com/package/minimatch
  ],
};

You can also set up a callback hook in config file:

module.exports = {
  onFinish: (result) => {
    // ...
  } 
};

The callback will be invoked after lint finish running and the results will be passed through.

mono-ts-check's People

Watchers

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