News for hackers. Stuff that matters.
Re:TypeScript 5.0 by quonn on Thursday March 16, 2023 @03:00PM (#35186676)
The missing feature I want most is type narrowing across chained functions like:

arr.filter(a => a.kind === β€žbarβ€œ).map(a => /* a should now be of type Bar just like in a branch */)

Re:TypeScript 5.0 by acdibble on Thursday March 16, 2023 @03:14PM (#35186874)
Re:TypeScript 5.0 by subarctic on Thursday March 16, 2023 @03:13PM (#35186854)
Wait, are you saying they added that in this release? That's awesome!
Re:TypeScript 5.0 by dhritzkiv on Thursday March 16, 2023 @06:01PM (#35189393)
This is not part of this release.
Re:TypeScript 5.0 by silasdavis on Thursday March 16, 2023 @03:51PM (#35187421)
It was would be nice for this to be automatic but filter does work like this it you pass a type guard as the predicate:

``` arr.filter((a: A): a is A & { kind: 'bar'} => a.kind === 'bar') ```

If you define:

``` function isKind<K extends A['kind']>(kind: K): (a: A) => a is A & { kind: K } { return (a): a is A & { kind: K } => a.kind === kind; } ```

Then you can write:

``` arr.filter(isKind('bar')) ```

and get a properly narrowed return type array

Re:TypeScript 5.0 by quonn on Friday March 17, 2023 @04:37PM (#35202589)
Nice, thank you