You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the return type of a function that may return the result of a recursive call, will always be inferred as Unknown | type_of_known_return_paths.
For example, the return type of the following function is inferred as Unknown | None:
defrecurse(i: int):
ifi>0:
returnrecurse(i-1)
If I'm not mistaken, if the types of all return paths are either known (in this case it's just None) or are the result of a recursive call, then the only other possible return type would be NoReturn.
Therefore, we could narrow the return type of the above function to a more precise NoReturn | None.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently, the return type of a function that may return the result of a recursive call, will always be inferred as
Unknown | type_of_known_return_paths
.For example, the return type of the following function is inferred as
Unknown | None
:If I'm not mistaken, if the types of all return paths are either known (in this case it's just
None
) or are the result of a recursive call, then the only other possible return type would beNoReturn
.Therefore, we could narrow the return type of the above function to a more precise
NoReturn | None
.Beta Was this translation helpful? Give feedback.
All reactions