Skip to content

Type inference of generic method arguments, in the body of the child class. #43638

@qwabra

Description

@qwabra

Bug Report

🔎 Search Terms

Type inference of generic method arguments, in the body of the child class.

⏯ Playground Link

namespace Base {
    export interface EventsList {
        [k: string]: (...args: any) => void
    }
}
declare class Base<T extends Base.EventsList> {
    emit<E extends keyof T, A extends Parameters<T[E]>>(event: E, ...args: A): boolean
}
// -,-
namespace A {
    export interface EventsList extends Base.EventsList {
        event1(n: number): void
    }
}
class A<T extends A.EventsList> extends Base<T> { }
// -,-
namespace B {
    export interface EventsList extends A.EventsList {
        event2(str: string): void
    }
}
class B<T extends B.EventsList> extends A<T> {
    t() {
        // -,-
        type event1 = T["event1"] // (method) A<T extends A.EventsList>.EventsList.event1(n: number): void
        // type event1 = (n: number) => void // OK <-------------------
        type parameters = Parameters<event1>
        const params: parameters = [1] // Type '[number]' is not assignable to type 'parameters'.(2322)
        // const params: Parameters<T["event1"]> = [1] // Type '[number]' is not assignable to type 'Parameters<T["event1"]>'.(2322)
        // -,-
        this.emit('event1', 1) // FAIl
    }
}
// -,-
{//test
    const instance = new B
    instance.emit('event1', 1)
    instance.emit('event2', 'q')
    // instance.emit('qwqwqwq', 'qwqwqwq') // ?
    // instance.emit('') // No suggestions
}

Workbench Repro

🙁 Actual behavior

    t() {
        // -,-
        type event1 = T["event1"] // (method) A<T extends A.EventsList>.EventsList.event1(n: number): void
        // type event1 = (n: number) => void // OK <-------------------
        type parameters = Parameters<event1>
        const params: parameters = [1] // Type '[number]' is not assignable to type 'parameters'.(2322)
        // const params: Parameters<T["event1"]> = [1] // Type '[number]' is not assignable to type 'Parameters<T["event1"]>'.(2322)
        // -,-
        this.emit('event1', 1) // FAIl
    }

🙂 Expected behavior

    t() {
        this.emit('event1', 1)
    }
        // type event1 = T["event1"] // should work like
        type event1 = (n: number) => void 
  1. suggestions in instance.emit('')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions