Skip to content

Function overload breaks generics #29312

@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.1.6

Search Terms: overload function generic

Code

declare function identity <T extends unknown>(t: T): T
declare function identity (): undefined

declare class Option<A> {
  chain<B>(f: (a: A) => Option<B>): Option<B>;
}

// Actual type: <T>(option: Option<Option<T>>) => Option<{}>
// Expected type: <T>(option: Option<Option<T>>) => Option<T>
// Disabling second `identity` overload fixes it for some reason.
const optionFlatten = <T>(option: Option<Option<T>>) => option.chain(identity)

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