Skip to content
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

Accessing property on super should be a type error #35314

Closed
trusktr opened this issue Nov 23, 2019 · 2 comments · Fixed by #54056
Closed

Accessing property on super should be a type error #35314

trusktr opened this issue Nov 23, 2019 · 2 comments · Fixed by #54056
Labels
Bug A bug in TypeScript

Comments

@trusktr
Copy link
Contributor

trusktr commented Nov 23, 2019

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

@fatcerberus
Copy link

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.

@Jack-Works
Copy link
Contributor

#54056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants