Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Latest commit

 

History

History
75 lines (59 loc) · 1.62 KB

ban-types.md

File metadata and controls

75 lines (59 loc) · 1.62 KB

Enforces that types will not to be used (ban-types)

Bans specific types from being used. Does not ban the corresponding runtime objects from being used.

Rule Details

Examples of incorrect code for this rule "String": "Use string instead"

class Foo<F = String> extends Bar<String> implements Baz<String> {
    constructor(foo: String) {}

    exit(): Array<String> {
        const foo: String = 1 as String;
    }
}

Examples of correct code for this rule "String": "Use string instead"

class Foo<F = string> extends Bar<string> implements Baz<string> {
    constructor(foo: string) {}

    exit(): Array<string> {
        const foo: string = 1 as string;
    }
}

Options

{
    "typescript/ban-types": ["error", {
        "types": {
            // report usages of the type using the default error message
            "Foo": null,

            // add a custom message to help explain why not to use it
            "Bar": "Don't use bar!",

            // add a custom message, AND tell the plugin how to fix it
            "String": {
                "message": "Use string instead",
                "fixWith": "string"
            }
        }
    }
}

Example

{
    "typescript/ban-types": [
        "error",
        {
            "types": {
                "Array": null,
                "Object": "Use {} instead",
                "String": {
                    "message": "Use string instead",
                    "fixWith": "string"
                }
            }
        }
    ]
}

Compatibility