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
An explicitly typed function whose return type isn't the Void or the Any type must have at least one return statement somewhere in its body
to
An explicitly typed function whose return type isn't the Void type, the Any type, or a union type containing the Void or Any type as a constituent must have at least one return statement somewhere in its body
It would be nice if Promise didn't require a return statement in an async function. However for the issue I had the already proposed change would be enough.
An explicitly typed function whose return type isn't the Void type, the Any type, or a union type containing the Void or Any type as a constituent must have at least one return statement somewhere in its body
Isn't the emphasized part redundant? The following already compiles:
function f(): number | any {
}
I think the union resolution already recognizes that all types are subtypes of any, so any union involving any is just any.
Activity
RyanCavanaugh commentedon Jan 4, 2016
Proposing changing spec section 6.3
to
DanielRosenwasser commentedon Jan 4, 2016
That still doesn't actually cover
Promise<void>
on its own though.RyanCavanaugh commentedon Jan 4, 2016
Not sure I understand the comment
DanielRosenwasser commentedon Jan 4, 2016
The change you're proposing doesn't permit an async function whose return type annotation is
Promise<void>
to have no return statements.RyanCavanaugh commentedon Jan 4, 2016
I don't think anyone would want that behavior (@Pajn, care to weigh in?)
Pajn commentedon Jan 4, 2016
It would be nice if Promise didn't require a return statement in an async function. However for the issue I had the already proposed change would be enough.
RyanCavanaugh commentedon Jan 5, 2016
Approved, accepting PRs. Should be easy.
masaeedu commentedon Jan 15, 2016
@RyanCavanaugh Regarding:
Isn't the emphasized part redundant? The following already compiles:
I think the union resolution already recognizes that all types are subtypes of
any
, so any union involvingany
is justany
.RyanCavanaugh commentedon Jan 15, 2016
I think that's an implementation side effect of the compiler. The spec doesn't specify that
number | any
is equivalent to the Any type, though.