Skip to content

Regression: constructor accessor not allowed on plain objects #52443

Closed
@mhofman

Description

@mhofman

Bug Report

Since 4.8.0, TypeScript errors when defining a constructor accessor on plain objects. Likely as a side-effect of #48954

🔎 Search Terms

constructor accessor object

🕗 Version & Regression Information

  • This changed between versions 4.7.4 and 4.8

⏯ Playground Link

Playground Link: Provided

Output
"use strict";
const foo = {
    get constructor() {
        return {};
    }
};
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,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

💻 Code

const foo = {
  get constructor() {
    return {};
  }
};

🙁 Actual behavior

Class constructor may not be an accessor. ts(1341)

🙂 Expected behavior

No error for non class cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions