Skip to content

[bug] Auto accessor fields are declared as regular properties in mixin abstract classes #60672

Open
@TechQuery

Description

🔎 Search Terms

abstract class mixin accessor field property declaration .d.ts ts(2611)

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241203#code/PTAEAMEsDsBMFMAeA6WyAuBncpKdAObzTwBOAhuvLKAEYCeEWAxqALRvwC2k6AIvGYAbchXSQA9tADy0IfRwwIXemyGRaFUgoBQSAA4TS6UAmGj4ocrUzoKzE+cz4AQuUyWA3jtC+rzZnhnIysALlBoAFcuWjIAbh0AXz1EQ2NTQRFSSwAzSOgHSWhQHlhYIXgACgBlSP0yAH5w9Hp6iRzQNw8ASnDrW3sTEgB3UEru0ABeAD5Qbz8wiOjY0gTEhJBcLjSTTxLIMorQRNAc0gkuUAByFTUNLXorhIMjRxFnUAAxGHIhUCQqHB8KVylUJvM-OQAkFMCFyFNQAAmOK+TZYSqIgBsAEZsRMyOdSEkgA

💻 Code

// `index.d.ts` is generated by `tsc --emitDeclarationOnly` in `my-library`
declare abstract class Base {
    accessor a: number;
}
declare function middle(Super?: typeof Base): abstract new () => {
    a: number;
};
// import { middle } from 'my-library';
class Final extends middle() {
    accessor a = 2;  // ts(2611) error
}

🙁 Actual behavior

TS throws:

'a' is defined as a property in class '{ a: number; }', but is overridden here in 'Final' as an accessor. ts(2611)

but the library source code is:

export abstract class Base {
    accessor a = 1;
}

export function middle(Super = Base) {
    abstract class Middle extends Super {
    }
    return Middle;
}

🙂 Expected behavior

It has no type error while overrides auto accessor fields in sub classes of abstract mixins from 3rd-party libraries.

Additional information about the issue

This bug can be resolved if tsc generates .d.ts as shown below:

// `index.d.ts` is generated by `tsc --emitDeclarationOnly` in `my-library`
declare abstract class Base {
    accessor a: number;
}
declare function middle(Super?: typeof Base): abstract new () => {
-    a: number;
+    get a(): number;
+    set a(value: number);
};
// import { middle } from 'my-library';
class Final extends middle() {
    accessor a = 2;  // no error
}

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241203#code/PTAEAMEsDsBMFMAeA6WyAuBncpKdAObzTwBOAhuvLKAEYCeEWAxqALRvwC2k6AIvGYAbchXSQA9tADy0IfRwwIXemyGRaFUgoBQSAA4TS6UAmGj4ocrUzoKzE+cz4AQuUyWA3jtC+rzZnhnIysALlBoAFcuWjIAbh0AXz1EQ2NTQRFSSwAzSOgHSWhQHlhYIXgACgBlSP0yAH5w9Hp6iRzQNw8ASnDrW3sTEgB3UEru0ABeAD5Qbz9CeBNycfComPifPw9lyoA3ciFI+DXo2NJuhMSEkFwuNJNPEsgyitBE0BzSCS5QAHIVGoNFp6H8EgYjI4RM5QAAxGCHUBIKhwfClcpVCbzPzkAJBTAhchTUAAJjivluWEqJIAbABGOkTMjfUhJIA

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions