Skip to content

Function overload breaks generics #29312

Closed

Description

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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