Content-Length: 313925 | pFad | https://github.com/microsoft/TypeScript/issues/6102

22 allow a flag that turns off covariant parameters when checking function assignability · Issue #6102 · microsoft/TypeScript · GitHub
Skip to content

allow a flag that turns off covariant parameters when checking function assignability  #6102

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

Currently the following flawed code is permitted:

interface A { x: nuber; }
interface B { x: number, y: string }
function copyB(value: B) : B {
   return { x: value.x, y: value.y };
}
let values : A[] = [];
let copied= values.map(copyB); // <-- no problem compiling, but a problem at runtime

Thank to the following line: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/checker.ts#L5654

I suggest to give developers a flag that would disable such unsound behavior allowing function subtyping the way it is supposed to be: https://en.wikipedia.org/wiki/Subtyping#Function_types.

An outline of a pull request of how this might look like: https://github.com/aleksey-bykov/TypeScript/commit/34b8f9b5a937cb7bb471771d5c9b9c4d4f629fc8

Related issues: #5961, #3523, #4895, #5741, #3067, #222, #5673

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/microsoft/TypeScript/issues/6102

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy