Hacker News new | ask | show | jobs
by tayo42 443 days ago
In some cases don't you need to actually execute the code to know what the type actually is. How does the type checker know then?
1 comments

It doesn't. There are cases where the type-checker can't know the type (e.g. json.load has to return Any), but there are tools in the language to reduce how much that happens. If you commit to a fully strictly-typed codebase, it doesn't happen often.
You can actually annotate the return type of json.load better than that:

    JSON = float | bool | int | str | None | list[“JSON”] | dict[str, “JSON”]