Suppose I have the following interface that defines a function:
export declare interface NavigationGuard {
(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext): NavigationGuardReturn | Promise<NavigationGuardReturn>;
}
The goal is to create this type:
export SomeNavigationGuardType = (to: RouteLocationNormalized, from: RouteLocationNormalized): NavigationGuardReturn | Promise<NavigationGuardReturn>
Working with the original NavigationGuard
type ...
I've attempted to use the utility type Parameters
, extracting and utilizing Omit
to remove the next parameter, but the Parameters
utility type extracts to a tuple.
I've tried using:
type NavigationGuardParams = Omit<Parameters<NavigationGuard>, 'next'>
export type UseRouterNivigationGuards = {
beforeEach?: (arg: NavigationGuardParams) => ReturnType<NavigationGuard>
beforeResolve?: (arg: NavigationGuardParams) => ReturnType<NavigationGuard>
afterEach?: NavigationHookAfter
}
and
type NavigationGuardParams = Omit<Parameters<NavigationGuard>, 'next'>
export type UseRouterNivigationGuards = {
beforeEach?: (...arg: NavigationGuardParams) => ReturnType<NavigationGuard>
beforeResolve?: (...arg: NavigationGuardParams) => ReturnType<NavigationGuard>
afterEach?: NavigationHookAfter
}
However, both attempts result in a usage/parameter error, with the first giving this message:
Expected 1 argument, but received 2.
The second attempt produces:
Argument of type '[RouteLocationNormalized, RouteLocationNormalized]' cannot be assigned to a parameter of type 'NavigationGuardParams'.
Is there a workaround to achieve this?