typescript - Transformă constructorul Boolean într-un gard de tip


Este un model comun să folosești constructorul Boolean într-un array .filter(/* ... */) pentru a elimina valorile false.

Există vreo modalitate prin care să pot transforma constructorul Boolean într-un gardian de tip care elimină valorile nullabile? Încerc să fac ceva de genul celui de mai jos:

const list = ['foo', 'bar', null];

// how can I make this line not error?
const onlyStrings: string[] = list.filter(Boolean as <T>(t: T) => t is NonNullable<T>);

Dar primesc următoarea eroare:

Conversion of type 'BooleanConstructor' to type '<T>(t: T) => t is NonNullable<T>' may be a mistake because neither type sufficiently overlaps with the other

Vreo idee?

Link către terenul de joacă