Skip to content

Getter not functioning properly when overriding the setter #56336

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

Closed
andrewl913 opened this issue Nov 7, 2023 · 2 comments
Closed

Getter not functioning properly when overriding the setter #56336

andrewl913 opened this issue Nov 7, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@andrewl913
Copy link

🔎 Search Terms

setter without getter abstract class

overriding a setter on a base class causes the subclass getter to return undefined

The getter not functioning properly when overriding the setter.

🕗 Version & Regression Information

Tested on v3, v4, and v5.

The getter not functioning properly when overriding the setter.

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/FASwdgLgpgTgZgQwMZQAQAUYHsAmBXJCAZQgWlQG9hVUQcAuVAZwhnAHMBua1MBAWyiMWbMFx4syeJsNYduAX2DAEAIxHIIqJABsETJhmz5CAHiKooAD2hgchzLgLFS5ALxGnhEmSgA+Sh4kLDARZywYAAoAB2xoQigcVAASSWhGIgBKQJolHnYoLTpI7KoaGhhCvBgwVAgACxAmADpU1yhmuh4lGgKtNOkSnPLKiGrahqbWtI6Bpm5c5RomQuZXQYA3BB08ITXRdlKeGkmWtt9mudQPLZ2oBdQlPPBoeGQ0ACEsLABrH3JrLZ7J4TC5fMM+IJZAcHk1VGBofJgHldPpDF9fpYbFA7A5jM5TBi-u0AmVmKs5pFbrtEWIjuVtCEmFgdB0dFh2JEAERELCCZh0KAAWigcDgUEIqHqsA6XMyDxOjTOM0u60MN22uweT2UwVCWlU3x+114UAA7qgiZEKLwBHsuQAVKAsLkAGjWUhkqC5AEFCCANlA3bQGN6AIzBuEI8MAJgAzFzHvLgHrmazmuzOYbfqrPfKgA

💻 Code

interface ProductState {
  id: string;
  name: string;
  status: string;
}

abstract class Product<S extends ProductState = ProductState> {
  constructor(protected $state: S) {
  }

  get id() {
    return this.$state.id
  }
  get status() {
    return this.$state.status;
  }

  set status(value: string) {
    this.$state.status = value;
  }
}

interface BookState extends ProductState {
  name: string;
  isbn: string;
}

class Book extends Product<BookState> {
  set status(value: string) {
    console.log("Some side-effect here.");
    this.$state.status = value;
  }
}

const book = new Book({ name: "Test", status: "Active", id: "1", isbn: "123" });
// Returns undefined
console.log(book.status);

🙁 Actual behavior

the field status returns undefined.

🙂 Expected behavior

the field status returns "Active".

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

MartinJohns commented Nov 7, 2023

Duplicate of #47581. Used search terms: getter setter in:title

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 7, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants