eslint-plugin-ban-type-assertion

0.0.2 • Public • Published

Ban specified Typescript type assertions (as MyType and <MyType>) (ban-type-assertion)

Allow type assertions to certain types to be banned. Built-in types may not be banned.

Rule Details

This rule allows you to specify a list of types that you don't want to be used as type assertions.

These examples assume that the following configuration is specified:

{
    "rules": {
        "ban-type-assertion": ["error", {"typeName": "BannedType", "message": "Do not coerce to BannedType. Instead use the constructor createBannedType"}, {"typeName": "AnotherBannedType"}']
    }
}

Examples of incorrect code for this rule:

const x = foo as BannedType;
const x = <BannedType>foo;

Examples of correct code for this rule:

const x = foo as AllowedType;
const x = <AllowedType>foo;
// Built-in types may not be banned
const x = foo as string;

Options

This rule takes an array of objects with the following properties:

  • typeName: The name of the type to ban.
  • message: The message to display when the type is banned. This property is optional.

Package Sidebar

Install

npm i eslint-plugin-ban-type-assertion

Weekly Downloads

215

Version

0.0.2

License

MIT

Unpacked Size

3.66 kB

Total Files

4

Last publish

Collaborators

  • zgotsch