Skip to content
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

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

Open
TechQuery opened this issue Dec 3, 2024 · 1 comment · May be fixed by #60853
Open

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

TechQuery opened this issue Dec 3, 2024 · 1 comment · May be fixed by #60853
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@TechQuery
Copy link

TechQuery commented Dec 3, 2024

🔎 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

@Andarist
Copy link
Contributor

Andarist commented Dec 3, 2024

I believe this is related to #44938 and #58790 . They involve intersections though and yours doesnt but ultimately all of them are about accessors serialization

EDIT:// I might have spoken too soon. After further analyzing this and the related issues - the other ones are really just about intersected getters whereas this one is purely about accessors serialization. Note though that it's not exclusive to accessors. Getters and setters are prone to this too: TS playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants