Post

What if TypeScript had an `unsafe` keyword and `as`, ‘any`, and `!` were only available inside of blocks declared as `unsafe`?

Philippe Serhal@philippeserhal.com

TypeScript RFC: `as` → `unsafe_as` `any` → `unsafe_any` `!` → `!!!` and a tsconfig strict flag to disallow each (I know linters support this already!)

1 repost12 likes

You could disallow any in function arguments and then you’d use unknown and cast as any in the unsafe block

I think it might be fine to still have any and unknown as types for parameters but as soon as you want to do something with them like access a property or cast them, you have to put them in an unsafe block. I heard pointers in rust work similar?