Git Product home page Git Product logo

tsquickfix's Introduction

Quick fixes in TypeScript

Quick fixes are coming in TypeScript, scheduled in 2.1 (see the Roadmap)

This is great in a lot of scenarios:

  • In your editor, you'll have the "just fix it please" action.
  • You'll usually fix errors before checking in your code, but for warnings it's cool to hook up your code review tool to suggest/apply fixes for issues it highlights.
  • We use it for big-codebase janitoring. When a new error is added to the compiler (like --noImplicitReturns say) we can apply a fix automatically against all of Angular for example.

Try it out

Here's a program with a simple diagnostic:

problem

If you pull microsoft/TypeScript#9304 you can build a TypeScript that knows how to fix some diagnostics. (I did it a month ago, that work is now split into more PRs).

Since this isn't available in any editors yet, I wrote a little command-line harness to run it and just print the diff it would apply:

fix

The red text would be removed and the green text would be added.

Thanks https://github.com/paulvanbrenk - this will be cool ๐Ÿ˜„

Quick fixes in TSLint

My intern, https://github.com/ScottSWu just finished up his summer working on TSLint.

We wanted to be able to make style changes across Google's TS code. So he added the ability for TSLint checks to propose code changes: palantir/tslint#1423

Then he added a fix for the type-assertion rule, where you can pick between <string>s or (s as string) - at Google our style guide prefers the latter.

We wrote a tool to automatically correct all the code with wrong style.

VSCode has special support for TSLint

Before fixes were part of TSLint, the VSCode team put up a contrib rule set which has quick fixes wired to a TSLint VSCode extension. Using the .vscode/settings.json in this repo, I can fire up VSCode and see a lightbulb next to a style issue:

lightbulb

and clicking that gives you the chance to apply the fix:

suggestion

I look forward to getting the new fixes in TSLint hooked up to VSCode and other editors!

tsquickfix's People

Contributors

alexeagle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.