Skip to main content
  1. About
  2. Stack Internal
The 2026 Annual Developer Survey is live— take the Survey today!
Commonmark migration
Source Link
Community Bot
  • 1 reputation score 1
  • 1
  • 1 silver badge

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

export function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.

    I need a way to express that A needs to be a class.

  • I also need to express the return type, which yields several errors, among:

    I also need to express the return type, which yields several errors, among:

    error TS4060: Return type of exported function has or is using private name 'B'.

error TS4060: Return type of exported function has or is using private name 'B'.

Additional information:

  • This is inside a utils.ts module that is exported so that other modules can use it
  • This is all being worked in the context of a library I am writing

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

export function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.
  • I also need to express the return type, which yields several errors, among:

error TS4060: Return type of exported function has or is using private name 'B'.

Additional information:

  • This is inside a utils.ts module that is exported so that other modules can use it
  • This is all being worked in the context of a library I am writing

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

export function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.

  • I also need to express the return type, which yields several errors, among:

    error TS4060: Return type of exported function has or is using private name 'B'.

Additional information:

  • This is inside a utils.ts module that is exported so that other modules can use it
  • This is all being worked in the context of a library I am writing
added 191 characters in body
Source Link
franleplant
  • 669 reputation score 669
  • 1
  • 1 gold badge
  • 7
  • 7 silver badges
  • 19
  • 19 bronze badges

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

export function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.
  • I also need to express the return type, which yields several errors, among:

error TS4060: Return type of exported function has or is using private name 'B'.

Additional information:

  • This is inside a utils.ts module that is exported so that other modules can use it
  • This is all being worked in the context of a library I am writing

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.
  • I also need to express the return type, which yields several errors, among:

error TS4060: Return type of exported function has or is using private name 'B'.

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

export function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.
  • I also need to express the return type, which yields several errors, among:

error TS4060: Return type of exported function has or is using private name 'B'.

Additional information:

  • This is inside a utils.ts module that is exported so that other modules can use it
  • This is all being worked in the context of a library I am writing
Source Link
franleplant
  • 669 reputation score 669
  • 1
  • 1 gold badge
  • 7
  • 7 silver badges
  • 19
  • 19 bronze badges

Implement Pure Class mixins with Typescript

Im trying to define a pure class based mixin function, but I cannot get the type signature right for this one.

The intent is to provide a function that accepts any Class A as parameter and returns a new Class B that extends the original Class A.

function mixin<A>(myclass: A) {
  return class B extends A {
    newMethod() {
      //stuff
    }
  }
}

As I said, I cannot figure this out.

  • I need a way to express that A needs to be a class.
  • I also need to express the return type, which yields several errors, among:

error TS4060: Return type of exported function has or is using private name 'B'.

lang-js
Morty Proxy This is a proxified and sanitized view of the page, visit original site.