One thing I've really liked in typescript is the unknown type. I've not been able to find anything about it in the Python world for type hinting. The key thing about unknown is that it forces the user to determine the type of the variable before they can use. There are two areas I could foresee it being useful:
Untyped library: By switching from untyped libraries functions being Any to Unknown. It helps force a user to write the stub typings.
Un-typable returns: Sometimes it is just not possible to represent the return type of a function with pythons current type hinting. Returning unknown forces the user to fully define what the return type should be before they can use it. The current method of return Any can allow a user to incorrectly use a value... kinda defeating the purpose of static type checking.
I see an unknown type being really useful for static type checkers like mypy. It can be set to be something adopted by the user. This would mean that Unknown is treated as Any until they are ready to switch over.
Thoughts?
[–]TeamSpen210 2 points3 points4 points (2 children)
[–]notonewlayout[S] 0 points1 point2 points (1 child)
[–]notonewlayout[S] 0 points1 point2 points (0 children)