My advice is to avoid any
as much as humanly possible.
“Unknown” is problematic by definition, but generics do a great job of handling “not completely known”:
“Optional” is easy. You can “or” together union types like string | number
, and Foo | undefined
is equivalent to "optional Foo
". This is such a common construct that there’s syntactic sugar for it: foo?: Foo
.
There are also utility types that allow you to turn properties from required to optional (or vice versa) using a more generic syntax.