Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow partially specified type arguments #6344

Closed
zpdDG4gta8XKpMCd opened this issue Jan 4, 2016 · 1 comment
Closed

allow partially specified type arguments #6344

zpdDG4gta8XKpMCd opened this issue Jan 4, 2016 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@zpdDG4gta8XKpMCd
Copy link

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);
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jan 7, 2016
@mhegazy mhegazy added the Declined The issue was declined as something which matches the TypeScript vision label Feb 24, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Feb 24, 2016

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

@mhegazy mhegazy closed this as completed Feb 24, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants