Microsoft/TypeScript
Auf GitHub ansehenOverload order affects assignability of abstract constructors overloaded with regular constructors in interfaces
Open
#59.890 geöffnet am 7. Sept. 2024
BugDomain: IntersectionHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
🔎 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
💻 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