Menu

Post image 1
Post image 2
1 / 2
0

Extending my TypeScript auto-fix CLI to handle .filter(Boolean) narrowing issues

DEV Community·i-am-killvish·28 days ago
#ogmgUnvO
Reading 0:00
15s threshold

A few days ago I shared a small CLI experiment called fixmyfile that automatically fixes repetitive TypeScript errors using compiler diagnostics and AST transformations. While testing it more, I kept running into another frustrating TypeScript pattern: const users = data . filter ( Boolean ); users . map (( u ) => u . name ); Enter fullscreen mode Exit fullscreen mode Even after filtering values, TypeScript can still complain that: 'u' is possibly undefined Enter fullscreen mode Exit fullscreen mode Logically the values are already filtered, but TypeScript narrowing does not always behave the way developers expect. So I started experimenting with AST-based transformations for these cases too. Now the CLI automatically converts: const users = data . filter ( Boolean ); Enter fullscreen mode Exit fullscreen mode into: const users = data .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More