1

In typescript, the Parameters<T> utility type returns a tuple. How would I get the same thing but as an object?

type Idk<T> = //...

declare function createUser(id: string, userType: UserEnum): Option<User>;

// [id: string, userType: UserEnum]
let params: Parameters<typeof createUser>;

// {id: string, userType: UserEnum}
let paramsObj: Idk<typeof createUser>;
kalkronline
  • 459
  • 2
  • 12
  • 1
    You can't do that. – jcalz Aug 11 '22 at 21:11
  • 1
    What would that even mean? JavaScript doesn't have named parameters, only positional ones. – jonrsharpe Aug 11 '22 at 21:11
  • 3
    See the answer to the linked question for more information; basically the answer is either "no" or "you can only do it if you manually map parameter positions to property names like `SomeType`" (which is a long way of saying "no" unfortunately) – jcalz Aug 11 '22 at 21:15
  • 1
    Yeah, thanks, clarifying that the labels on the tuple are cosmetic is very helpful. – kalkronline Aug 11 '22 at 21:20

0 Answers0