Skip to content

Commit 0a1f3b6

Browse files
author
aleph-naught2tog
committed
Disallows async abstract method declarations
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.
1 parent 204ce17 commit 0a1f3b6

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28342,6 +28342,9 @@ namespace ts {
2834228342
if (flags & ModifierFlags.Private) {
2834328343
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "private", "abstract");
2834428344
}
28345+
if (flags & ModifierFlags.Async) {
28346+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "async", "abstract");
28347+
}
2834528348
}
2834628349

2834728350
flags |= ModifierFlags.Abstract;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/abstractAsync.ts(2,9): error TS1243: 'async' modifier cannot be used with 'abstract' modifier.
2+
3+
4+
==== tests/cases/compiler/abstractAsync.ts (1 errors) ====
5+
abstract class ShouldFailClass {
6+
async abstract badMethod(): Promise<number>;
7+
~~~~~~~~
8+
!!! error TS1243: 'async' modifier cannot be used with 'abstract' modifier.
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [abstractAsync.ts]
2+
abstract class ShouldFailClass {
3+
async abstract badMethod(): Promise<number>;
4+
}
5+
6+
//// [abstractAsync.js]
7+
var ShouldFailClass = /** @class */ (function () {
8+
function ShouldFailClass() {
9+
}
10+
return ShouldFailClass;
11+
}());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/abstractAsync.ts ===
2+
abstract class ShouldFailClass {
3+
>ShouldFailClass : Symbol(ShouldFailClass, Decl(abstractAsync.ts, 0, 0))
4+
5+
async abstract badMethod(): Promise<number>;
6+
>badMethod : Symbol(ShouldFailClass.badMethod, Decl(abstractAsync.ts, 0, 32))
7+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/abstractAsync.ts ===
2+
abstract class ShouldFailClass {
3+
>ShouldFailClass : ShouldFailClass
4+
5+
async abstract badMethod(): Promise<number>;
6+
>badMethod : () => Promise<number>
7+
>Promise : Promise<T>
8+
}

tests/cases/compiler/abstractAsync.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @lib: es2015
2+
abstract class ShouldFailClass {
3+
async abstract badMethod(): Promise<number>;
4+
}

0 commit comments

Comments
 (0)