Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Fix TypeScript declarations. (#173)
Browse files Browse the repository at this point in the history
* Fix TypeScript declarations.

* Another round of fixes

* Reverting some of the last fixes

This should work the way the previous build was designed to.

For anywhere that needs hooks to appear on a Service, you need to include:

```typescript
import "feathers-hooks"
```

...at the top of your file. Then the `Service` and `Application` merged declarations will be present in the file. At least I'm finding that to produce clean TypeScript builds right now.
  • Loading branch information
TimMensch authored and daffl committed Oct 22, 2017
1 parent d660ff9 commit 9e2add6
Showing 1 changed file with 43 additions and 44 deletions.
87 changes: 43 additions & 44 deletions index.d.ts
@@ -1,52 +1,51 @@
import * as feathers from 'feathers';
import * as feathers from "feathers";

declare module 'feathers' {
interface Application {
hooks(hooks: hooks.HooksObject): Application;
}
declare function hooks(): () => void;

interface Service<T extends any> {
before(hooks: hooks.HookMap): Application;
after(hooks: hooks.HookMap): Application;
hooks(hooks: hooks.HooksObject): Application;
}
declare module "feathers" {
interface Service<T> {
before(hooks: hooks.HookMap): Application;
after(hooks: hooks.HookMap): Application;
hooks(hooks: hooks.HooksObject): Application;
}
interface Application {
hooks(hooks: hooks.HooksObject): Application;
}
}

declare function hooks(): () => void;

declare namespace hooks {
interface Hook {
<T>(hook: HookProps<T>): Promise<any> | void;
}

interface HookProps<T> {
app?: feathers.Application;
data?: T;
error?: any;
id?: string | number;
method?: string;
params?: any;
path?: string;
result?: T;
service: feathers.Service<T>;
type: 'before' | 'after' | 'error';
}

interface HookMap {
all?: Hook | Hook[];
find?: Hook | Hook[];
get?: Hook | Hook[];
create?: Hook | Hook[];
update?: Hook | Hook[];
patch?: Hook | Hook[];
remove?: Hook | Hook[];
}

interface HooksObject {
before?: HookMap;
after?: HookMap;
error?: HookMap;
}
interface Hook {
<T>(hook: HookProps<T>): Promise<any> | void;
}

interface HookProps<T> {
app?: feathers.Application;
data?: T;
error?: any;
id?: string | number;
method?: string;
params?: any;
path?: string;
result?: T;
service: feathers.Service<T>;
type: "before" | "after" | "error";
}

interface HookMap {
all?: Hook | Hook[];
find?: Hook | Hook[];
get?: Hook | Hook[];
create?: Hook | Hook[];
update?: Hook | Hook[];
patch?: Hook | Hook[];
remove?: Hook | Hook[];
}

interface HooksObject {
before?: HookMap;
after?: HookMap;
error?: HookMap;
}
}

export = hooks;

0 comments on commit 9e2add6

Please sign in to comment.