iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😖

I Created a Repository of Ways to Break Type Safety in TypeScript

に公開

Practical statically typed languages usually have backdoors for doing dangerous things[1], but TypeScript is unique in that these backdoors often exist in places that aren't obvious at first glance.

So, I've tried writing unsafe_cast<T, U>(x: T): U in various ways. Quite handy.

https://github.com/todesking/unsafety-zoo.ts/tree/master/src

Acknowledgments: Many of these techniques are based on an article by Mr. tkr.
https://kgtkr.net/blog/2018/06/23/typescript-unsafe

脚注
  1. Scala's asInstanceOf[T], Haskell's unsafeCoerce, OCaml's Obj.magic, ... ↩︎

Discussion