question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idea: Type Unpackers for Function Parameters

See original GitHub issue

Because of TypeScript 2.8 Conditional Types, we can now do the following:

type Param0<Func> = Func extends (a: infer T, ...args: any[]) => any
	? T
	: never;
type T0 = Param0<() => void>; // {}
type T1 = Param0<(a: number) => void>; // number
type T2 = Param0<(a: string[]) => void>; // string[]

Issue for discussion!

Questions:

  • Naming scheme?
  • Multiple Parameter Unpacks at the same time?

See also ReturnType<Func>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pelotomcommented, Jun 14, 2018

On second thought you may be right about performance being a concern… I agree it might be better to play it safe.

1reaction
pelotomcommented, Jun 14, 2018

ArgumentsType seems more consistent, in line with arguments as well as (...args: any[]).

Parameters are the declared inputs of a function signature, arguments are the runtime objects passed to a function:

https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter

@pelotom Is there a performance concern re: unpacking the whole array by default? If people are mostly going to access a single parameter, maybe we should consider that?

I really doubt there’s much performance difference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unpack to function parameters - c++ - Stack Overflow
Is it theoretically possible to add a language feature to unpack structures into the function actual parameter lists? I mean the following.
Read more >
Packing and unpacking parameters - Google Groups
For passing parameters to functions I want to pack them into a vector p, ... I can write two functions p = pack(a,b,c)...
Read more >
A Guide to Args, Kwargs, Packing and Unpacking in Python
Before we get more into packing and unpacking values in Python, let's talk a little more about function arguments. There are 2 kinds...
Read more >
Extract Parameter | IntelliJ IDEA Documentation - JetBrains
The Extract Parameter refactoring lets you extract a new parameter to a method. You can also use the Extract Functional Parameter ...
Read more >
Using Python Optional Arguments When Defining Functions
The double star is used to unpack items from a mapping. A mapping is a data type that has paired values as items,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found