-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Abstract methods should not allow async
modifier
#28516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Since we do not allow `async` as a modifier on type members such as in an interface, it was decided that it should also not be allowed on abstract methods. Fixes microsoft#28516.
Since we do not allow `async` as a modifier on type members such as in an interface, it was decided that it should also not be allowed on abstract methods. Fixes microsoft#28516.
@DanielRosenwasser should we also disallow class C {
async foo(); // <- should this be disallowed?
async foo() {
}
} |
Mmm, I don't know; seems like that's okay since the following is allowed. async function foo(): Promise<number>
async function foo() {
return Promise.resolve(10);
} Thoughts @RyanCavanaugh? |
There is actually a runtime difference between an An I just don't know if this is something TS is capable of reasoning about. |
@DanielRosenwasser your example of allowed code is just how the |
Personally, requiring the They even have different prototypes (that differ in But that ship sailed long before I even started learning JavaScript 😓 |
@Kovensky: That isn't the issue at question here. The issue is whether to disallow |
It seems related to me because of the contract I just mentioned. An I guess this is kind of a broader point about having |
@Jessidhia Your argument is actually why abstract class Base {
abstract async foo(): Promise<number>
}
class Derived {
foo(): Promise<number> {
throw new Error()
}
}
const base: Base = new Derived()
base.foo() // Throwable |
* Prisma Client now requires TypeScript v4.1 or above. See: https://github.com/prisma/prisma/releases/tag/2.14.0 * Fixes: Abstract methods should not allow an async modifier in the same way an interface and other type parameters don't allow them. See: microsoft/TypeScript#28516
Uh oh!
There was an error while loading. Please reload this page.
This had already been discussed here which was a different issue that was concluded to be intended behaviour, but that abstract methods allowing
async
was not intended.TypeScript Version: Version 3.2.0-dev.20181113
Search Terms:
abstract async, async
Code
Expected behavior:
Abstract methods should not allow an
async
modifier in the same way an interface and other type parameters don't allow them.Actual behavior:
Abstract methods do not error with an
async
modifier attached; interface methods do.Playground Link: Both of these should error, not just the second on, as discussed in the earlier linked issue. Reproduced here
Related Issues:
Originally discussed in the comments in here, where the consensus was that the behavior was intended for that case, but that
async abstract
should not be allowed.The text was updated successfully, but these errors were encountered: