Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Compiles without error when the return type signature of variable doesn't match that of the generic function that it is being assigned to #5616

Copy link
Copy link
@prateekbhatt

Description

@prateekbhatt
Issue body actions

Compiling the code below:

function identity<T>(arg: T): T {
    return arg;
}

var myIdentity: <T>(arg: T) => string = identity;

var a = myIdentity<string>("string")
var b = myIdentity<number>(100)

outputs the following javascript:

function identity(arg) {
    return arg;
}
var myIdentity = identity;
var a = myIdentity("string");
var b = myIdentity(100);

I put the type signature of the variable myIdentity as <T>(arg: T) => string
where the return type is string instead of T (that I expect to be correct).

I expected the Typescript compiler to show an error because the return types
don't match. However, the code compiled without any error.

Specs:

Mac OS X 10.11

tsc --version outputs:
message TS6029: Version 1.6.2

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueA PR has been merged for this issueIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.