Skip to content

aleung/tslint-strict-error-throw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tslint-strict-error-throw

This rule enhances and replaces the TSLint core rules no-string-throw (which equals to ESLint no-throw-literal).

It restricts that only instances or subclasses of Error be thrown.

Example – Doing it right

throw new Error("message");

class Exception extends Error {
    // ...
}
const exception = new Exception("message");
throw exception;

Example – Anti Pattern

throw "error";

throw { message: "error" };

class MyError {
    // ...
}
throw new MyError();

Note This rule requires type information to run. Click to learn more.

Install

You should already install tslint.

yarn install --dev tslint-strict-error-throw

Usage

In tslint.conf extend the configuration preset provided by this package. It disables no-string-throw (from tslint-core) and enables tslint-strict-error-throw.

"extends": [
  ...
  "tslint-strict-error-throw"
]

About

Custom tslint rule to restricts that only instances or subclasses of Error be thrown.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published