Skip to content

[Feature Request] A way to instruct how to infer this #15836

Closed
@bigopon

Description

@bigopon

TypeScript Version: 2.3.2

Code

I have this definition:

extend<T, K>(cls: (...args: {}[]) => T, xtn: K): new (...args: {}[]) => T & K

Usage:

var NewClass = extend(MyClass, {
  init(a) {
    this.doSomething();
  },

  // ....
})

The NewClass will still have all expected method init ..., but the this cannot be inferred inside the extension object.

It would be great if there is a way to instruct Typescript how to infer the this inside extension object based on the first passed param meter. (MyClass in the example). The reason is to have better intellisense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThe issue relates to how you learn TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions