Skip to content

[bug] statements not allowed in front of super() call #31925

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

Closed
trusktr opened this issue Jun 15, 2019 · 2 comments
Closed

[bug] statements not allowed in front of super() call #31925

trusktr opened this issue Jun 15, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@trusktr
Copy link
Contributor

trusktr commented Jun 15, 2019

TypeScript Version: 3.5.2

Search Terms:

Code

            constructor(options = {}) {
                console.log('hello')
                super(options)
            }

Expected behavior:

It should work. It's valid JavaScript.

Run the following in Chrome console (or one that support class fields):

class A {
	foo = 'foo'
	constructor() {
		this.foo = 'bar'
	}
}

class B extends A {
	bar = 'bar'
	constructor() {
		console.log('hello')
		super()
		this.bar = 'foo'
	}
}

new B()

Actual behavior:

It complains:

A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.

Playground Link:

playground link

Related Issues:

@Epskampie
Copy link

Duplicates: #945 #8277 etc etc. Please search before posting!

@trusktr
Copy link
Contributor Author

trusktr commented Jun 15, 2019

Ah, ok. Thanks. 🙏 Sorry!

@trusktr trusktr closed this as completed Jun 15, 2019
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants