Closed as not planned
Closed as not planned
Description
π Search Terms
filter narrow destructuring
π Version & Regression Information
This is recent functionality, in 5.5, I think? (type narrowing via array filter functions).
β― Playground Link
π» Code
async function x() {
return 'hello';
}
(await Promise.allSettled([x()]))
.filter((s) => s.status === "fulfilled") // narrows type to PromiseFulfilledResult<string>[]
.map(({ value }) => value);
(await Promise.allSettled([x()]))
.filter(({ status }) => status === "fulfilled") // does not narrow type
.map(({ value }) => value); // unsure that value exists
π Actual behavior

π Expected behavior
Expect the destructured version to narrow the element type as well.
Additional information about the issue
I found #28311 when searching for existing bugs, looks like it can be closed by the existing 5.5 features, good work!