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

Compiler allows violation of a generic function type interface #11877

Closed
albrow opened this issue Oct 27, 2016 · 2 comments
Closed

Compiler allows violation of a generic function type interface #11877

albrow opened this issue Oct 27, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@albrow
Copy link

albrow commented Oct 27, 2016

TypeScript Version: 2.0.6

Code

interface GenericIdentityFn {
    <T>(arg: T): T;
}

function identity(n: number): string {
    return n.toString();
}

let myIdentity: GenericIdentityFn = identity;

Expected behavior:

The code should not compile because identity does not satisfy the constraints of GenericIdentityFn. Namely, it accepts an argument of type number and returns type string, whereas the interface GenericIdentityFn describes a function that accepts an argument of type T and returns type T.

Actual behavior:

The code compiles.

Other notes:

This is based on an example from https://www.typescriptlang.org/docs/handbook/generics.html.

@HerringtonDarkholme
Copy link
Contributor

Related #11537

@mhegazy
Copy link
Contributor

mhegazy commented May 18, 2017

Tracked by #5616

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 18, 2017
@mhegazy mhegazy closed this as completed May 18, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants