Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: option to warn instead of failing build #232

Closed
dallonf opened this issue Mar 18, 2019 · 9 comments
Closed

Feature request: option to warn instead of failing build #232

dallonf opened this issue Mar 18, 2019 · 9 comments

Comments

@dallonf
Copy link

dallonf commented Mar 18, 2019

It would be very useful to put this plugin in a mode where type errors are treated as equivalent to lint warnings, instead of failing the build. Maybe something like maximumSeverity: 'warn'?

@johnnyreilly
Copy link
Member

What would the use case of that be?

@dallonf
Copy link
Author

dallonf commented Mar 18, 2019

I'm currently working on a major refactor of my codebase and certain parts of it I know are not working and certainly are not type-correct at the moment. I'm OK with that and I really just need to test the parts that should be working right now.

And in general, my team's mental model of TypeScript is that of a lint tool / test suite, and we are more often annoyed by type errors preventing us from testing the app on the local dev server than helped (most of our lint rules are also set to Warn for this reason). My ideal set up would be one that warns of type errors in the console but does not stop the app from working locally. (obviously, type errors should still cause CI build failures!)

@johnnyreilly
Copy link
Member

johnnyreilly commented Mar 18, 2019

I'll have to admit to being appalled by your attitude towards static typing; surely you must want to be entirely type safe right now with no delay 😁

That said, there's room in the world for multiple opinions. If you'd like to consider a PR to that end I'll certainly look at it.

@kelly-tock
Copy link

I also would like this. here's my use case:

  • with incremental flag turned on, it happens really fast, so 👍
  • however, with this on, you may want to set async to be false again, as it is fast so no worries, and it integrates with plugins better
  • but now you have to fix all TS errors first before you see/test your code. when refactoring/doing a new feature it's nice to be able to see it working while you're going and clean up as you go.

@johnnyreilly
Copy link
Member

Cool - if someone wants to submit a PR we'll take a look. 😊

@piotr-oles
Copy link
Collaborator

@dallonf , @kelly-tock
Please try fork-ts-checker-webpack-plugin@alpha - I've published a new version which allows you to filter out issues using predicates (issues options) 🚀
I will close this issue to clean-up the backlog :)

@aspirisen
Copy link

@piotr-oles As i understand the issues option doesn't show errors from TypeScript. Is it possible to show errors from TS but as warnings (yellow) and don't break webpack. Just for soft migration to from js to ts.

@piotr-oles
Copy link
Collaborator

To do that, you can use issues hook. The most convenient way to do that is to create a custom plugin. I wrote this pseudo-code to show you an idea:

import webpack from 'webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';

class ForkTsCheckerWarningWebpackPlugin implements webpack.Plugin {
  apply(compiler: webpack.Compiler) {
    const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
    
    hooks.issues.tap(
      'ForkTsCheckerWarningWebpackPlugin',
      (issues) => issues.map(issue => ({ ...issue, severity: 'warning' }))
    );
  }
}

export { ForkTsCheckerWarningWebpackPlugin }

@chrisalley
Copy link

Thank you @piotr-oles. Here is a solution that I adapted from your example for webpack 5:

typescript-warn-only-webpack-plugin.js

const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");

class TypeScriptWarnOnlyWebpackPlugin {
  apply(compiler) {
    const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);

    hooks.issues.tap("TypeScriptWarnOnlyWebpackPlugin", (issues) =>
      issues.map((issue) => ({ ...issue, severity: "warning" }))
    );
  }
}

module.exports = TypeScriptWarnOnlyWebpackPlugin;

webpack.config.js

const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const TypeScriptWarnOnlyWebpackPlugin = require("./typescript-warn-only-webpack-plugin");

module.exports = {
  plugins: [
    new ForkTsCheckerWebpackPlugin(),
    new TypeScriptWarnOnlyWebpackPlugin(),
  ],
  ignoreWarnings: [/warning from compiler/, (warning) => true],
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants