microsoft / microsoft/TypeScript

super reference in private method throws

Open
#44,515 2 comments 5 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Jun 9, 2021.

Bug Domain: classes Rescheduled
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

private, super

🕗 Version & Regression Information

v4.3.2, also tested with nightly in playground

works with ESNext setting (which just strips out the types), Babel, V8

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.3.2#code/MYGwhgzhAECC3QN4CgEIC4FMLoBQEolU0SAnTdAV1IDtoByLHe4hAX2Q+VEhgCFomAB5YaAExjwUJAMQAzAPYKCREmQrU6ESgAdMpAHRM8+VtC4kARmFIrpahOSq1o6ABYBLCAflKCZji5gBRocaEtoAF5oGkwAd2g+AgNrW1NuEIgFEEwDEAUAc1xLfCA

💻 Code
class A  {
    test() {
        return 'test'
    }
}

class B extends A {
    #foo() {
        return super.test()
    }

    bar() {
        return this.#foo()
    }
}

const b = new B().bar()

console.log(b)

// [ERR]: "Executed JavaScript Failed:" 
// [ERR]: 'super' keyword unexpected here 
🙁 Actual behavior

throws error

🙂 Expected behavior

prints 'test'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.