#Is it possible to make the Function Parameters to an options Type?

1 messages · Page 1 of 1 (latest)

gilded wasp
#

Given this example:

oak flareBOT
#
cristobal#4241

Preview:```ts
// Custom interface from playwrights type defintion file
interface Page {
waitForRequest(
urlOrPredicate: string|RegExp|((request: Request) => boolean|Promise<boolean>),
options?: {
timeout?: number;
}
): Promise<Request>;

goto(url: string, options?: {
...```

gilded wasp
#

Is it possible to make the result from the Parameters into a an options type e.g.:

type OptionsFromFuntionArguments = ParametersToObject<Parameters<Page['waitForRequest']>[0]>;

// Such that we can access the arguments by name or use it as an options type e.g.?
type ArgumentType = OptionsFromFuntionArguments['urlOrPredicate']

export function (page: Page, options: OptionsFromFuntionArguments) {
  ..
}
gilded wasp
#

Is it possible to the Function Parameters to an options Type?

gray frost
#

afaik u cant access the label/name in tuples

gilded wasp
#

kk, that's what i thought

#

However TypeScript knows the tuple names from the function that the Parameters utility was applied on

#

That's why i thought it could possible…

#

Is it possible to make the Function Parameters to an options Type?

deft pawn
#

you probably just want Parameters<typeof myFunc>[number]

oak flareBOT
#
LittleLily#6666

Preview:```ts
...
type OptionsFromFuntionArguments<
T extends (...args: any) => any

= Parameters<T>[number]
...```

gilded wasp
#

not quite…

#

now i get an union type

#

i want this

gilded wasp
#

Seems like its not doable at all as mentioned earlier by @gray frost