This PR improves the types of filter such that it better handles user-defined type guards. This idea was taken from @nordfjord's work here: https://github.com/paldepind/flyd/pull/173
Example.
function isString(a: any): a is string {
return typeof a === "string";
}
// A list containing elements of several different types
const l = L.list<number | string>(0, "one", 2, "three", 4, "five");
// After filtering with the type guard the returned list will now have a more precise type
const l2 = L.filter(isString, l);
// TypeScript now knows that l2 contains only strings :)
const l3 = L.map(s => s.padStart(6), l2);
This PR improves the types of
filter
such that it better handles user-defined type guards. This idea was taken from @nordfjord's work here: https://github.com/paldepind/flyd/pull/173Example.