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

not inferring expression signature match on generics #32314

Closed
Samsinite opened this issue Jul 9, 2019 · 3 comments
Closed

not inferring expression signature match on generics #32314

Samsinite opened this issue Jul 9, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Samsinite
Copy link

TypeScript Version: 3.5.2

Search Terms: no compatible call signatures

Code

  type Success<T> = {
    tag: 'success';
    value: T;
    fbind<R, E>(func: (value: T) => Result<R, E>) : Result<R, E>;
  }
  
  type Failure<E> = {
    tag: 'failure';
    error: E;
    fbind<T, R>(_func: (value: T) => Result<R, E>) : Result<R, E>;
  }
  
  type Result<T, E> = Success<T> | Failure<E>;
  
  function success<T>(value: T) : Success<T> {
    return {
      tag: 'success',
      value,
      fbind<R, E>(func: (value: T) => Result<R, E>): Result<R, E> {
        return func(this.value);
      },
    };
  }
  
  function failure<E>(error: E) : Failure<E> {
    return {
      tag: 'failure',
      error,
      fbind<T, R>(_func: (value: T) => Result<R, E>) : Result<R, E> {
        return this;
      },
    };
  }
  
  type ValidationError = string;
  
  function parseDate(value: string) : Result<Date, ValidationError> {
    // simple example to show issue
    return success(new Date(value));
  }
  
  function logDate(date: Date) : Result<Date, ValidationError> {
    console.log('Date: ', date);
    return success(date);
  }
  
  parseDate('1-1-2019').fbind(logDate);

But, the following code runs without errors, which is strange:

const result = parseDate('1-1-2019');

if (result.tag === 'success') { 
  result.fbind(logDate);
} else if (result.tag === 'failure') { 
  result.fbind(logDate);
}

Expected behavior: No errors

Actual behavior: Cannot invoke an expression whose type lacks a call signature. Type '(<R, E>(func: (value: Date) => Result<R, E>) => Result<R, E>) | (<T, R>(_func: (value: T) => Result<R, string>) => Result<R, string>)' has no compatible call signatures.

Playground Link: http://www.typescriptlang.org/play/#code/C4TwDgpgBAygrgYwRAzigPAFQHxQLxQDeUAUFFMAIYDmAXFAOQqLJoMDcZUAbpQDZwI9TJ3IAzAEYBLAHYATdACUANFACi2ABRi4MhPU28BQqJgCU+XItRw+wJao0X615nYfrsnAL4kSoSCgAMUopAQAnCHQNfCJScio6RjFQiIgOLghw8IB7cPo1UShJWQVMVUUtAH0dPQMjQWELPCsbdxVPZyhXW3sOjR8-AOge93LPWPgkVAwcKAAfYNS4SOivP1qEYCkcmShmabQsLQaTcyh6KdZZ3GIuSOAVvbvyBJp6JhYZhmUuclPfq9itJ5B4NNpdPooIZ+I1TM1Wm4+o5sGYXG1kRMXkCoA8nsVIZpgAALKQoAB0pzMRXI3kBUG8gxIm22u2Ky1W4KyuXy6i6ITCKyiMWxePCz3ir0SHxSgsiPz+UG5eXp4hBZQq1U29VhZwR3QxYNRFwNSKNcUV5DFexJZJpDPpjJIvn84GgADV+FI5JRWTI1Nk8rEUMBwrJqJxmZC-VAwJRwigIAARX0QGHGeghsMyahdUb2FPACCqT18b2+nb+wPhW6SgD0df2UgAtmA+NAIAAPSit9sUHL7Yk5ADuUDJzAg9wgj3F+y+aE0Mggo8LabMZmdG2jlagfBy1FXmh9Rfoq7zhtXJa9x8rAZ5ta4CF2KBy7fJe+omgYq4+qmPEGpKcZz2A5riPVNAJdOME2TVMvwARgAWiQgAmAAGeCAE4GDMckSnkTQPzPSMnxkENcQxWJoMTQ8GCQ1CMOwwCSCkMRoUiJFyUSfA8AIT5DhQHCLStDE8PVQj92I50lT4RMxzYzQON6LiaB4vjZTSITRVE-C5Akg8IJ8IA

Related Issues: None that I could find

@jcalz
Copy link
Contributor

jcalz commented Jul 9, 2019

Duplicate of #7294

Despite more support added for calling unions of functions in TS3.3, it is still not possible to call unions of multiple generic function signatures. It's not trivial to implement that.

@Samsinite
Copy link
Author

Samsinite commented Jul 9, 2019

Is there an issue that is open for this feature? Unless support for this is not planned, seems like it would be a good idea to keep an issue open for tracking this issue/feature, thoughts?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 10, 2019
@RyanCavanaugh
Copy link
Member

Issues are open if they have identifiable near-term work to do, which isn't the case here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants