Skip to content

mapped intersection loses type information #30545

@kolodny

Description

@kolodny

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:
"mapped types", "overload", "intersection"

Code

type ReturnObjects<T> = {
    [K in keyof T]: T[K] extends ((...args: any[]) => any) ?
    T[K] & Returnable<T[K]> :
    never
}

type Returnable<Fun extends (...args: any[]) => any> = {
    returnValue(val: ReturnType<Fun>): void;
}

interface I {
    f(): string;
    f(x: any): number;
}

let argsObj: ReturnObjects<I>;
argsObj.f.returnValue(1) // OK
argsObj.f.returnValue('1') // ERROR?!```

Expected behavior:

argsObj.f.returnValue('1') should not cause a type error

Actual behavior:

argsObj.f.returnValue('1') causes a type error

Playground Link

Related Issues: Couldn't find anything

Note that if I switch the order of the interface, it will only expect the other overload. I believe that typescript is overriding the previous value and not intersecting them

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