Microsoft/TypeScript

Subclass of a (non-abstract class that uses declaration merging to implement parent abstract member) also has to implement same abstract member

Open

#57,263 创建于 2024年2月1日

在 GitHub 查看
 (0 评论) (1 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: classesHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

subclass inherit abstract concrete method property member complains parent declaration merge merging satisfy implement

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed all the FAQ entries

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.3#code/JYOwLgpgTgZghgYwgAgApyhcBJZBvAKGWORgHsyAKASgC5kA3M4AEwIF8C4AjAZzCiIwyBABs4vXmgxZhhEsh79BCYeSp1GzNpwIB6PcgCyrFqJTAAtgAdzl2VPSZwjYHGQsIYjHDDAyIMj2UADmEAQE3pLGpubIEAAekCAsjjIueJygkLCIKCYsZiiJyanSzmC4mRFRUgDCABbAoizxSVhlBUX47MgGHmQQvCAA5MIA7mRQANYR-V1xVrYQ9uBpFR7AmKqiAJ6R4tELEABMbaXrsvhEJOo0PRw1h-VNLWclHVLHZ5l9hpMzXhAA

💻 Code

interface ParentI {
    foo(): void
}
abstract class Parent {
    abstract foo(): void
}

// Middle implements Parent via declaration merge

class Middle extends Parent {}
interface Middle extends ParentI {}

class Child extends Middle {} // doesn't work

// Middle implements Parent directly
class Middle2 extends Parent {
    foo() {}
}

class Child2 extends Middle2 {} // works

🙁 Actual behavior

Typescript complains that Child must implement an foo, even though Middle has already implemented foo via declaration merging.

🙂 Expected behavior

I would expect Child to pass type-checking, just as Child2 does. Seeing as how Middle (a concrete class) is type-safe and Child extends Middle with no further modification, this feels very surprising.

Additional information about the issue

No response

贡献者指南