GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make functions generic when contextually typed by a generic signature · Issue #5737 · microsoft/TypeScript

Make functions generic when contextually typed by a generic signature #5737

New issue
Copy link
New issue
Copy link
Closed
Closed
Make functions generic when contextually typed by a generic signature#5737
Copy link
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript

Description

@zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)
opened on Nov 20, 2015
Issue body actions
type Foo = (one: string) => number;

function fooOver() : Foo {
    return one => parseInt(one); // <-- one is string
}

type Bar = <a>(one: string) => a;

function barOver() : Bar {
    return one => parseInt(one); // <-- one is god knows what
}

Activity

  1. Ryan Cavanaugh (RyanCavanaugh)
    added
    BugA bug in TypeScriptA bug in TypeScript
    on Nov 20, 2015
  2. RyanCavanaugh commented on Nov 20, 2015

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Nov 20, 2015
    Member
    More actions

    Technically this is according to per spec (I know, your favorite response), but I think we should do better here.

    Section 4.2.3 (https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#423-contextually-typed-expressions) says

    In the body of a function expression or arrow function that has no return type annotation, if the function expression or arrow function is contextually typed by a function type with exactly one call signature, and if that call signature is non-generic, return expressions are contextually typed by the return type of that call signature.

    We already said that we should contextually type parameters when type annotations are present somewhere --- no reason we shouldn't contextually type using the non-generic parameter positions or non-generic return positions.

  3. Ryan Cavanaugh (RyanCavanaugh)
    added
    SpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
    on Nov 20, 2015
  4. Anders Hejlsberg (ahejlsberg)
    added a commit that references this issue on Dec 3, 2015

    Merge pull request #5737 from Microsoft/unionIntersectionTypeInference

    b022893
  5. ahejlsberg commented on Dec 7, 2015

    @ahejlsberg
    Anders Hejlsberg (ahejlsberg)
    on Dec 7, 2015
    Member
    More actions

    Ryan Cavanaugh (@RyanCavanaugh) There is no easy way to tell whether a particular type references a type parameter and I honestly think that we either contextually type all parameters or none. Anything in between just gets even more confusing.

  6. Mohamed Hegazy (mhegazy)
    added
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    In DiscussionNot yet reached consensusNot yet reached consensus
    and removed
    BugA bug in TypeScriptA bug in TypeScript
    SpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
    on Dec 8, 2015
  7. Daniel Rosenwasser (DanielRosenwasser)
    changed the title [-]another inferrence strangeness[/-] [+]Make functions generic when contextually typed by a generic signature[/+] on Aug 21, 2016
  8. Ryan Cavanaugh (RyanCavanaugh)
    closed this as completedon Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.