Skip to content

Invalid await is generated in constructor when initializing field #34887

Closed
@brianush1

Description

@brianush1

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms: invalid await in constructor

Code

async function bar() {
	return 2;
}

async function foo() {
	return new class {
		baz = await bar();
	};
}

Expected behavior:
Error, as await cannot be used in a constructor

Actual behavior:
Invalid JS code is generated, as a constructor using await bar(); is generated, and this is not allowed in JS

Playground Link: http://www.typescriptlang.org/play/?ts=3.8.0-dev.20191101&ssl=1&ssc=1&pln=2&pc=11#code/IYZwngdgxgBAZgV2gFwJYHsIwEbAE4AUAlDAN4BQAkHgKbIJ5YBMA3OQL7nmiSyIoYscdOmJkqteoxgQaAdxhQANqBDjKlXAC8YAXhjA5wVMhz5ibSuzbsgA

Related Issues: None

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions