Skip to content

Void type and type parameters constraints #4654

Closed

Description

Spec for 1.6, p. 3.6.1 says:

Omitting a constraint or specifying type any as the constraint corresponds to specifying the empty object type {}.

This phrase is not clear, because the following code works:

function foo<A>() {
    return 2;
}
var x = foo<void>();

and the following code doesn't

function foo<A extends {}>() {
    return 2;
}
var x = foo<void>();

Could you please clarify what is meant by the word "corresponds" then?

Activity

  1. added
    Bug
    on Sep 4, 2015
  2. added
    Spec
    on Sep 7, 2015
  3. ahejlsberg commented on Sep 7, 2015

    @ahejlsberg
    Member

    We should remove that statement from the spec and instead say that

    • Any type can be a type argument for a type parameter that has no constraint, and
    • A type parameter with no constraint has the same apparent members as type {}.

    We can probably also remove the notion of a _base constraint_ as it isn't actually used anymore.

  4. removed
    Bug
    on Sep 10, 2015
  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Spec

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions