Skip to content

add in, out modifiers to allow being specific of expected contrvariant/covariant type parameters #8137

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

Problem: in the current state of affairs although convenient to certain audiences the bivariance is a gaping hole in the type system

Solution:

  • allow optional but explicit in and out modifiers like in C# for those who wants to take advantage of stricter typechecking
  • keep bivariant typechecking for anyone who doesn't care:
Array<a> {
   map:  <b>(map: (value: a) => b) => b[];
)

declare var animals: Array<Animal>;
declare var copyCat: (cat: Cat) => Cat

animals.map(copyCat); // expected not to typecheck, currently allowed no problem

// but if we go

Array<in a> {
   map:  <b>(map: (value: a) => b) => b[];
)

// then

animals.map(copyCat); // doesn't typecheck anymore as expected

#6102 spinoff

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions