Socket
Socket
Sign inDemoInstall

eslint-plugin-ban-type-assertion

Package Overview
Dependencies
102
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-plugin-ban-type-assertion

Disallow type assertions in TypeScript code


Version published
Weekly downloads
237
decreased by-31.5%
Maintainers
1
Install size
3.57 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 07 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc