TGViewer
Why Typescript is bad Why Typescript is bad @why_typescript_is_bad · 1.71K subscribers
Post #121 6.03K
Global declarations aren’t saved, but there is no other way to infer it. TS doesn’t respect JS standards.

Edit. TS claims to have a design goal of typing common JS patterns. The pattern in question is typeof of undeclared variable. Probably every reader used to do typeof window !== 'undefined' at least once.

It's currently possible to declare the variable globally by extending Window interface, but those declarations will be available — well — everywhere, including the modules that have nothing to do with them. Global variables, global declarations, all the globals are widely considered an antipattern for this reason.

Narrowing already makes it so that single variable can have several types in different parts of the code, but correctly typed typeof would also require dynamically changing a set of variables that are available in current scope.

It weren't us who made a decision about design goals, so the discussion on unintended consequences is under the feature request.
  • 💩 29
  • 🤨 4
  • 👍 1
  • 👎 1
  • 🤓 1
More from @why_typescript_is_bad
  1. Apr 25, 2025Playground @js_monk Thanks for sharing this madness!
  2. Mar 11, 2025TypeScript decided to commit sudoku by rewriting its compiler in an even worse language: G…
  3. Mar 7, 2025Also this was about running DOOM in types https://www.youtube.com/watch?v=0mCsluv5FXA
  4. Mar 7, 2025That's it.
  5. Jan 27, 2025photo post
  6. Jan 25, 2025Eh?
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →