Skip to content

JS Object.defineProperty declaration can't define divergent accessors #55505

Open
@Andarist

Description

@Andarist
Contributor

πŸ”Ž Search Terms

divergent accessors setter getter expando js jsdoc

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?filetype=js#code/MYewdgzgLgBAHjAvDA3gXwNwCgsHkBGAVgKbBQB0AJsQGYCWYxACgE4gAOxLUAngBRwANDABEUYtBHCUWGDAD0AKkUwAAi2JQAri0ipoLBgHM0MRfNkwjmvgEpUluRu27RI7HLSDLSlavYAhiwBALaoYFoh+FymAWYWchA2Afbo3mi22Fg0WmBkdOAwdBAgADYB4gBibCEAonCBYJQgAIIQEHRGYCHEYFAQAEIMlMZ2DnJw5OLQSDAALABMGAryMFxsLDD4WrAQABYgWqWUW8QwuADSWGhYQA

πŸ’» Code

const x = {};

Object.defineProperty(x, "test", {
  /** @returns {string} */
  get() {
    return "";
  },
  /** @param {number} a */
  set(a) {},
});

function isolateFromExpandoAssignmentsBinding() {
  x.test = 42; // error but should be OK
}

πŸ™ Actual behavior

The write type of this expando member is string

πŸ™‚ Expected behavior

The write type of this expando member should be number since divergent accessors are allowed nowadays

Additional information about the issue

No response

Activity

changed the title [-]Expando object members can't define divergent accessors[/-] [+]JS `Object.defineProperty` declaration can't define divergent accessors[/+] on Aug 24, 2023
added this to the Backlog milestone on Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @andrewbranch@Andarist

        Issue actions

          JS `Object.defineProperty` declaration can't define divergent accessors Β· Issue #55505 Β· microsoft/TypeScript