Skip to content

cannot auto parse right type in these code #13844

Description

@ktangels

TypeScript Version: 2.1.4

Code

function mergeObject<T extends any>(dst: T, src: T): T
{
    for (var x in src)
    {
        dst[x] = src[x];
    }
    return dst;
}
 
interface Hash<T> { [key: string]: T; }

type EventHandler = (s: BaseEventDealer) => void;
interface BaseEventDealer
{
    GetEventHandler(event: string): EventHandler;
}

class C implements BaseEventDealer
{
    GetEventHandler(event: string) { return C.h[event]; }

    static h : Hash<EventHandler> = {
        a:function(s){}
    }
}

class D extends C
{
    GetEventHandler(event: string) { return D.h[event]; }
    static h = mergeObject<Hash<EventHandler>>(
        {
            b:function(s:D){}
        },C.h);
}

Expected behavior:

type of D.h should be Hash<EventHandler>
type of return value of D.GetEventHandler should be EventHandler

Actual behavior:

type of D.h and return value of D.GetEventHandler both is ImplicitAny
but if you remove D.GetEventHandler or change its name, h will get right type
or you manually declare h:Hash<EventHandler> or GetEventHandler(event: string):EventHandler, they will both get right type

Activity

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

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions