Skip to content

Accessing property on super should be a type error #35314

Closed
@trusktr

Description

@trusktr

TypeScript Version: 3.7.2

Search Terms:

typescript property access super undefined

Code

    class Base {
        n = 3
    }

    class Foo extends Base {
        test() {
            console.log(super.n) // type system says it should be a number, but it is undefined
        }
    }

    new Foo().test() // logs "undefined"

Expected behavior:

Should be some sort of type error, because clearly it is undefined

Actual behavior:

no error until runtime

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions