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

constructor overload of derived class should allow custom logic around calling super. #1272

Open
sylc opened this issue May 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@sylc
Copy link

sylc commented May 5, 2024

Lint Name

deno-lint(constructor-super)

Code Snippet

class Base {
    #name: string
    #index: number
    constructor(foo: { name: string, index: number }) {
        this.#name = foo.name
        this.#index = foo.index
    }
    print() {
        console.log(`${this.#name} - ${this.#index}`)
    }
}
 
class Derived extends Base {
    constructor(foo: string)
    constructor(foo: { name: string, index: number } | string) {
     if (typeof foo === "string") {
        super({ name: foo, index: 0 })
     } else {
        super(foo)
     }
    }
}

new Derived('hello').print()

Expected Result

No warning. (the ts playground site is happy with it as well)

Actual Result

image

Additional Info

Version

deno 1.43.1 (release, x86_64-pc-windows-msvc)
v8 12.4.254.12
typescript 5.4.3

workaround

As i was writing this I found a workaround (apart from disabling the lint)

class Derived extends Base {
    constructor(foo: string)
    constructor(foo: { name: string, index: number } | string) {
     let arg: { name: string, index: number } | string;
      if (typeof foo === "string") {
        arg = { name: foo, index: 0 }
     } else {
        arg = foo
     }
     super(arg)
    }
}
@sylc sylc added the bug Something isn't working label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant