Skip to content

Filter null in TypeScript #6

@rootEnginear

Description

@rootEnginear
const removeNull = (element: any): element is Exclude<typeof element, null> => !!element;

Usage

[1, true, null, 'lmao'].filter(removeNull) // [1, true, 'lmao'] with narrowed type 

Credit to @dtinth. From https://twitter.com/dtinth/status/1315714173242728448/photo/1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions