r/javascript • • Sep 14 '26

AskJS [AskJS] Does anyone use exclussively Javascript and not TypeScript?

[removed]

10 Upvotes

156 comments sorted by

View all comments

Show parent comment

1

u/AverageHot2647 Sep 19 '26

That’s a very unfortunate example 😂 Sounds like the reviewers didn’t know what they were doing if their solution is as unknown as T - this is almost never the solution and probably should also be flagged by a lint rule.

IMO cases like this is why lint ignore comments exist. You disable the rule and explain why the code is sound.

That said, you can use unknown in cases like this and then use runtime checks to narrow the type.

My general rule of thumb is if the answers to each of the following are “yes” then it’s ok to use the escape hatches TS intentionally provides:

  1. Is the implementation isolated? (I.e. any types or unchecked casts don’t escape from the local context)
  2. Is the implementation easy to verify manually?
  3. Would it be impractical to make the code type safe? (as unknown as T doesn’t count here)