Skip to content

Getters in mixins get serialized to property accessorsΒ #58790

Closed
@KonnorRogers

Description

@KonnorRogers

πŸ”Ž Search Terms

Getters, mixins, classes

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

https://tsplay.dev/mA0RkN

πŸ’» Code

function mixin<T extends {new (...args: any[]): {}}> (superclass: T) {
   return class extends superclass {
      get validationTarget (): HTMLElement {
         return document.createElement("input")
      }
   }
}
class BaseClass {
   get validationTarget (): HTMLElement {
      return document.createElement("div")
   }
}

class MyClass extends mixin(BaseClass) {
  get validationTarget (): HTMLElement {
   return document.createElement("select")
  }
}
Output
"use strict";
function mixin(superclass) {
    return class extends superclass {
        get validationTarget() {
            return document.createElement("input");
        }
    };
}
class BaseClass {
    get validationTarget() {
        return document.createElement("div");
    }
}
class MyClass extends mixin(BaseClass) {
    get validationTarget() {
        return document.createElement("select");
    }
}
Compiler Options
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

πŸ™ Actual behavior

The mixin creates a property accessor instead of a getter

πŸ™‚ Expected behavior

The mixin should create a getter and not a property accessor

Additional information about the issue

Seems related:

#54879 (comment)

Duplicate of: #44938

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issueHelp WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions