Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipe with no arguments should return an identity function type? #5557

Closed
lffg opened this issue Jul 2, 2020 · 0 comments
Closed

pipe with no arguments should return an identity function type? #5557

lffg opened this issue Jul 2, 2020 · 0 comments

Comments

@lffg
Copy link

lffg commented Jul 2, 2020

Type inference "bug" report

I'm new to this library, and I don't actually know if this is a by-design decision.

Current Behavior

When we use pipe with no arguments, an identity function is returned, as we can see here:

return identity as UnaryFunction<any, any>;

The problem is that the current type does not reflect this behavior, see (in the 5th line of that same file):

export function pipe<T>(): UnaryFunction<T, T>;

I think that, if we change that first overload to:

export function pipe(): typeof identity;

// Or:
export function pipe(): <T>(x: T) => T;
Diff
- export function pipe<T>(): UnaryFunction<T, T>; 
+ export function pipe(): typeof identity;

Or:

- export function pipe<T>(): UnaryFunction<T, T>; 
+ export function pipe(): <T>(x: T) => T;

The type inference would be more accurate, see:

Current type inference

// %inferred-type: UnaryFunction<unknown, unknown>
const fn = pipe();

// %inferred-type: unknown
const returnValue = fn('Foo');

Expectedtype inference

// %inferred-type: <T>(x: T) => T        /* (identity function type) */
const fn = pipe();

// %inferred-type: "Foo"
const returnValue = fn('Foo');

Environment

  • RxJS version: Latest (6.6.0 at the moment)

Should I open a pull request to fix this? Or is this behavior intentional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant