microsoft / microsoft/TypeScript

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

Open
#59,890 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Intersection Help Wanted
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground repro and compare assignability for interfaces and intersections containing abstract and regular constructor overloads in both orders. Trace the compiler's constructor overload and assignability checks, then verify that reversing overload order no longer changes the reported errors shown in the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.