Skip to content

allow partially specified type arguments #6344

Closed

Description

Currently when it comes to using generics a developer has 2 options:

  • to specify all type arguments
  • to omit all of them altogether

I am a big fan of the latter but it doesn't always work because of inference failure. Quite often it only takes one explicitly specified type argument to help the inference algorithm to deduce the rest of the types, but there is no such option to specify just one.

function fold<Values, Value, Cursor, Direction, Hint, Result>(
   values: Values,
   result: Result,
   start: (values: Values) => Cursor | void,
   advance: (cursor: Cursor) => Cursor | void,
   valueAt: (cursor: Cursor) => Value & Direction,
   hintAt: (cursor: Cursor) => Hint
   folding: (result: Result, value: Value & Direction, hint: Hint) => Result
) : Result {
return undefined;
}

Example. Almost everything is inferred but the Direction type parameter, which is specified explicitly via hypothetical syntax:

let result = fold<,,, AsTowardsLatest,,>(values, result, start, advance, valueAt, hintAt, folding);

Alternatively named arguments might be considered (hypothetical syntax)

let result = fold<Direction = AsTowardsLatest>(values, result, start, advance, valueAt, hintAt, folding);

Activity

  1. mhegazy commented on Feb 24, 2016

    @mhegazy
    Contributor

    This looks confusing, with little value. #2175 should be the way to go.

  2. 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

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions