Skip to content

no-useless-predicate: detect useless type guard calls #127

@ajafff

Description

@ajafff
declare function isString(v: any): v is string;
declare function isNumber(v: any): v is number;
declare let value: number;

// this condition will probably always be false, otherwise you have some really messed up code
if (isString(value)) {
    value.charAt(0);
}

// typeguard is useless because `value` is already `number` or a subtype thereof
if (isNumber(value)) {
    value.toFixed(0);
}

This needs type relationship APIs to detect if the typeguard type is not assignable to the original type.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions