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

Invalid argument candidate for this type inference #13323

Closed
edevine opened this issue Jan 6, 2017 · 1 comment
Closed

Invalid argument candidate for this type inference #13323

edevine opened this issue Jan 6, 2017 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@edevine
Copy link

edevine commented Jan 6, 2017

TypeScript Version: 2.1
The infered argument candidate 'string' is not considered valid when it should be.
Code:

class MyArray<T> extends Array<T> {
    flatten<R>(this: R[][]): R[] {
        return (new Array<R>()).concat(...this);
    }
}

var a = new MyArray<string>();
a.flatten<string>(); // Desired Error

var b = new MyArray<string[]>();
b.flatten<string>(); // string[]
b.flatten(); // Inference error

Expected behavior:
b.flatten() infers the type parameter as string and returns string[]

Actual behavior:

The type argument for type parameter 'R' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'string[]'.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 6, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jul 23, 2018
@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 23, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jul 23, 2018

Seems fixed in latest.

@mhegazy mhegazy closed this as completed Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants