Skip to content

Generic inference inside of pipe is incorrect when strict mode is disabled #25826

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 2.9.2

Search Terms:

Code

With strict mode disabled:

declare function pipe<V0, T1, T2, T3>(
    fn0: (x: V0) => T1,
    fn1: (x: T1) => T2,
    fn2: (x: T2) => T3,
): (x: V0) => T3;

type Option<T> = { t: T }
declare function optionOf<T>(value: T | null | undefined): Option<T>

declare function get(name: "set-cookie"): string[] | undefined;
declare function get(name: string): string | undefined;

// $ExpectType (x: {}) => Option<string>
// but got (x: {}) => Option<{}>
// Note: with strict mode enabled, we get the expected type.
const fn = pipe(
    ({}: {}) => 'foo',
    string => get(string),
    // Workaround: pass the function directly, instead of wrapping:
    // get,
    optionOf,
);

Related Issues:
This is similar to—but not exactly the same as—other issues I've filed when trying to use pipe:

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