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

Overload order affects assignability of abstract constructors overloaded with regular constructors in interfaces #59890

Open
bgenia opened this issue Sep 7, 2024 · 0 comments · May be fixed by #60000
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@bgenia
Copy link

bgenia commented Sep 7, 2024

🔎 Search Terms

abstract constructors, constructor overloading, overload order, intersection, type aliases, interfaces, assignability

🕗 Version & Regression Information

  • This seems like a bug
  • This is the behavior in every version I tried since abstract constructors were added (4.2)

⏯ Playground Link

https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&ts=5.7.0-dev.20240904#code/C4TwDgpgBAwgjFAvFAhgIwM7AE4oMbBQB2EA7lABQoBcUcAlEgHx0BQoksATEsWZTShdGiFl1asAlkWARsAM3zQAglAgAPWUQAmGWHAA03KAG8AvlAD0lqAFFs2APbZaMFESKPCKDBkkBzIlQg9CxcAig8RyIwgFcCZygOaGBHVGJogFpQnHxCKJiceNTsJPAIADopGTlFPGgAITVNCB09GC4jeFMLaygAeQBrCW0IPAAbFGxocYhvWmVWUYmpmbmoNFoGiT6AFQALCAxoVY2vfbV5eTHgSQA3CHGQVExcglYSchQKBiNP1Aowj+-DQP3owPIoOEEhQvDQVhsQ1Y8OQsL69icLlg7k83l8ARCIVe4Xy0TiCVKySSaVhniI2WJeUiZKKFLKkCq7HKUGUjIIADFJNgsLxugAybhczi8sJ5AAyPkIyA6UAl8BGY0m0ygs28fOAguFwAW+sNWCWmtOupesoICqwJttwHtwB2NgORxO2p8fkC6Fm1LU+AujkO2FYORJZqVNrezsVEf1Lt4kby0YkKNjUaFIvRDmcrhxXlQ+MCwSzTIK5JK7JSNIy9NTESrrJrySqTYNOZj8L6SORKaTioRA2GneTyF7iOGQA

💻 Code

type C1 = abstract new (a: 1) => 1
type C2 = new (a: 2) => 2

interface A extends C1, C2 {} // Error: Cannot assign an abstract constructor type to a non-abstract constructor type.
interface B extends C2, C1 {} // Ok

declare let a: A
declare let b: B

// These are both effectively abstract
new a(1), new a(2), new b(1), new b(2)

a = b // Ok
b = a // Error: Cannot assign an abstract constructor type to a non-abstract constructor type.

type AbstractFirst = C1 & C2
type AbstractLast = C2 & C1

declare let abstractFirst: AbstractFirst
declare let abstractLast: AbstractLast

// These are assignable to each oher
abstractFirst = abstractLast
abstractLast = abstractFirst

b = abstractFirst // Error: Cannot assign an abstract constructor type to a non-abstract constructor type.
abstractFirst = b // Ok

b = abstractLast // Ok
abstractLast = b // Ok

🙁 Actual behavior

It seems that interfaces with both abstract and regular constructor overloads are only assignable from types with non-abstract first constructor overload.

🙂 Expected behavior

I don't expect any difference here.

Additional information about the issue

No response

@bgenia bgenia changed the title Overload order affects assignability of abstract constructors extended with regular constructors between type aliases and interfaces Overload order affects assignability of abstract constructors overloaded with regular constructors in interfaces Sep 9, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Sep 13, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants