Skip to content

Accessing property on super should be a type error #35314

Closed

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

Activity

  1. fatcerberus commented on Nov 24, 2019

    @fatcerberus

    This might be a design limitation - TypeScript can’t currently distinguish between prototype properties and own properties of a class type. The type of super is Base, and Base-the-type has a property n, so the typechecker is satisfied.

  2. Jack-Works commented on Apr 29, 2023

    @Jack-Works
    Contributor
  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions