Skip to content

Commit

Permalink
fix(core): context.path is now typed correctly (#3303)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshotN authored Oct 11, 2023
1 parent 463dedc commit ff18b3f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/feathers/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { NextFunction, HookContext as BaseHookContext } from '@feathersjs/hooks'

type SelfOrArray<S> = S | S[]
type OptionalPick<T, K extends PropertyKey> = Pick<T, Extract<keyof T, K>>
type Entries<T> = {
[K in keyof T]: [K, T[K]]
}[keyof T][]
type GetKeyByValue<Obj, Value> = Extract<Entries<Obj>[number], [PropertyKey, Value]>[0]

export type { NextFunction }

Expand Down Expand Up @@ -355,6 +359,8 @@ export interface Http {

export type HookType = 'before' | 'after' | 'error' | 'around'

type Serv<FA> = FA extends Application<infer S> ? S : never

export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
/**
* A read only property that contains the Feathers application object. This can be used to
Expand All @@ -370,7 +376,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
* A read only property and contains the service name (or path) without leading or
* trailing slashes.
*/
readonly path: string
path: 0 extends 1 & S ? keyof Serv<A> & string : GetKeyByValue<Serv<A>, S> & string
/**
* A read only property and contains the service this hook currently runs on.
*/
Expand Down

0 comments on commit ff18b3f

Please sign in to comment.