3 ms·
I wish that TS had better type narrowing for the JS standard library, though there's a lot of constraints and design limitations that make it impractical. I ran
by DylanSp 3y ago
I wish that TS had better type narrowing for the JS standard library, though there's a lot of constraints and design limitations that make it impractical. I ran into a similar issue with the some() method on Array not narrowing types a while back [1]; that issue links to the same sort of issue with filter(), as well as issues where the TS team has discussed what they can and can't do in control flow analysis.
[1] https://github.com/microsoft/TypeScript/issues/40844 https://github.com/microsoft/TypeScript/issues/40844
- EvertBouw 3y agoyou can improve it a bit with the library ts-reset https://github.com/total-typescript/ts-reset https://github.com/total-typescript/ts-reset
- presentation 3y agoAnd also can declare your own wrappers to at least achieve it for your own codebase.