Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): context.path is now typed correctly #3303

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading