Skip to content

Generic lambda identity function can cheat typesystem easily #8397

@mpodlasin

Description

@mpodlasin

Hi. Before I start I want to emphasize that I googled a lot for that problem and found nothing. That being said, my problem seems to be so simple, that I am sure it was discussed before. If that is the case forgive me for spam. I would be just grateful for some link to the explanation of why TS works here the way it works.

I use TypeScript 1.8.10

So... this does not compile (which is good):

function id <A> (a : A) : A {
  return "string";
}

This however DOES (which for me seems super bad):

const id :<A>(a : A) => A = a => "string";

var x : number = id<number>(5); // compiler does not complain at all :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions