#Is it possible to make the Function Parameters to an options Type?
1 messages · Page 1 of 1 (latest)
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?: {
...```
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) {
..
}
Is it possible to the Function Parameters to an options Type?
afaik u cant access the label/name in tuples
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?
you probably just want Parameters<typeof myFunc>[number]
Preview:```ts
...
type OptionsFromFuntionArguments<
T extends (...args: any) => any
= Parameters<T>[number]
...```