Skip to content

class doesn't inherit generic type paramater when inheriting from a variable/expression #64116

Closed

Description

🔎 Search Terms

class inherit
generic constraint

🕗 Version & Regression Information

  • This changed between versions 7.1.0-dev.20260721.1 and 7.1.0-dev.20260722.1

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=23&ssc=32&pln=1&pc=1#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzDigxAGEcBbABzxFQwB4AFGHKgZ3hAA8TVhOAbwC+AGngBRAG50MnHnwHwRAPgAUAKHjb4cfiBgAuZVVYdjLNu3EgZ9dsemzOwjQEpjGAJ5UQORPDk1LT0DE72KgDcGhqgkLAI8eycQTSosmF2cly8dEoi8AC88ABK4DgwwAzsGDBYqADm4lCoXioqylo6YHg1MMiYFWpuXdoAJHgMANI5ipwA1iBe-pJZ7Oq2ssZT4gAWLcAQBsZqII5rANpTALpuRR1SOFjAHvCPz9GuGj2oNfAAQkUCEQSKkQhg1IJRvBoTp4KYrMYRKJYTpNvYkUgcDhjAByXHiRDYgBMeOJuPgrjhGmEbmiGnSAHcAcMAHQTVBqXFEnAE+CnO6FDoiOkMkDM-5sjlcnkAZj5Avuylp9KSKVmeU4gJEMSZgSleBl2IVIEFwpVYuZpANnO52Pl4kVQuVdKAA

💻 Code

declare function createComponent<Props extends {}, Events extends {}>(
    render: {props: Props, events: Events }
): typeof Component<Events>;

declare class Component<Events extends {} = Record<string, any>> {
    constructor()
    $on<K extends keyof Events>(event: K, handler: (e: Events[K]) => void): void;
}

const B = createComponent({    
        props: {},
        events: { foo: '', foo2: '2' }    
});

new B().$on('foo', (e) => {});
// error
new B().$on('foo3', (e) => {});

class C extends B {}

new C().$on('foo', (e) => {});
// no error
new C().$on('foo3', (e) => {});

🙁 Actual behavior

If I instantiate the derived B class directly, an error is reported, but not for the derived class. And if I remove the default generic type parameter from Component. A "Generic type 'Component' requires 1 type argument(s)." error will be reported on extends B. But this isn't reported in TypeScript 6 and TypeScript 7.0.2.

🙂 Expected behavior

Derived class retaining the generic type parameter.

Additional information about the issue

No response

Activity

  1. scs0209 commented on Sep 1, 2026

    @scs0209

    I'd like to work on this.

    I reproduced locally:

    • typescript@7.1.0-dev.20260722.1 — only new B().$on('foo3', …) errors; new C().$on('foo3', …) does not (bug)
    • typescript@7.1.0-dev.20260721.1 — both error as expected
    • Current main (253c5e20) built tsc shows the same regression

    Planning to bisect between the two nightlies and add a testcases regression test. If someone is already working on this, I won't proceed — just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions