Skip to content

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

Closed
@trusktr

Description

@trusktr

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:

Activity

Epskampie

Epskampie commented on Jun 15, 2019

@Epskampie

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

trusktr

trusktr commented on Jun 15, 2019

@trusktr
ContributorAuthor

Ah, ok. Thanks. 🙏 Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @trusktr@Epskampie@RyanCavanaugh

        Issue actions

          [bug] statements not allowed in front of super() call · Issue #31925 · microsoft/TypeScript