Microsoft/TypeScript
在 GitHub 查看Overload order affects assignability of abstract constructors overloaded with regular constructors in interfaces
Open
#59,890 创建于 2024年9月7日
BugDomain: IntersectionHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
🔎 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