Skip to content
Myr

fix(types): improve custom handler (#641)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent c14dd5a · Browse files · 3 files+21 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−11 removed

  • tests:+10 added−2 removed
  • other:+11 added−9 removed

3 files+21 added−11 removed

modified:src/context.ts+4 added-4 removed
9 unmodified lines
1011export interface Context<12 P extends string = string,13 E extends Partial<Environment> = Environment,14 S extends Partial<Schema> = Schema14 S extends Partial<Schema> | unknown = Schema15> {16 req: Request<P, SchemaToProp<S>>16 req: Request<P, S extends Schema ? SchemaToProp<S> : any>17 env: E['Bindings']18 event: FetchEvent19 executionCtx: ExecutionContext20 finalized: boolean
29 unmodified lines
50 E extends Partial<Environment> = Environment,51 S extends Partial<Schema> = Schema52> implements Context<P, E, S>53{54 req: Request<P, SchemaToProp<S>>54 req: Request<P, S extends Schema ? SchemaToProp<S> : any>55 env: E['Bindings']56 finalized: boolean57 error: Error | undefined = undefined58
12 unmodified lines
71 executionCtx: FetchEvent | ExecutionContext | undefined = undefined,72 notFoundHandler: NotFoundHandler<P, E, S> = () => new Response()73 ) {74 this._executionCtx = executionCtx75 this.req = req as Request<P, SchemaToProp<S>>75 this.req = req as Request<P, S extends Schema ? SchemaToProp<S> : any>76 this.env = env || ({} as Bindings)7778 this.notFoundHandler = notFoundHandler79 this.finalized = false
154 unmodified lines
modified:src/types.test.ts+10 added-2 removed
modified:src/types.ts+7 added-5 removed
50 unmodified lines
5152// This is not used for internally53// Will be used by users as `Handler`54export interface CustomHandler<55 P extends string | Partial<Environment> | Partial<Schema> = string,55 P extends string | Partial<Environment> | Schema = string,56 E = Partial<Environment> | Partial<Schema>,57 S = Partial<Schema>58> {59 (
9 unmodified lines
69 ? P70 : P extends Partial<Schema>71 ? Partial<Environment>72 : E extends Partial<Environment>73 ? E73 ? E extends Partial<Schema>74 ? Environment75 : E76 : E extends Partial<Schema>77 ? Partial<Environment>76 : never,78 : Environment,79 P extends Partial<Schema>80 ? P81 : E extends Partial<Schema>82 ? P extends Partial<Environment>83 ? E extends Partial<Environment>82 ? never84 ? unknown85 : E84 : never86 : unknown87 : S extends Partial<Schema>88 ? S89 : never90 >,
3 unmodified lines