Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    [1,2,undefined,3]
    .filter(<T>(x: T|undefined): x is T =>
        typeof x !== 'undefined'
    );
Yes builtin lang support would be better, but that gets you out of trouble in a pinch, without adding more 5 line npm baggage.

N.B. if you are in a JSX file, you'll need to add a comma: `<T,>`



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: