graphile/graphile-engine

InitObject is typed wrong

husseinhere opened this issue · 4 comments

I think:

export type InitObject = never;

instead of never, I think should be an-empty-object. It matters a little, because when you provide a hook function, now you need to trick typescript into thinking the function doesn't return. (But in fact, the function needs to return a true-y value)

Technically it should return the same value it was fed, not some alternative value. I think that works with TypeScript?

builder.hook('init', (_) => _)

Hm, I see what you're doing. It feels a little bit to me like the entire Hook is typed wrong, and should instead look more like:

export interface Hook<Type> {
  <T extends Type>(input: T, build: Build, context: Context<T>): T;
  displayName?: string;
  provides?: Array<string>;
  before?: Array<string>;
  after?: Array<string>;
}

And for the init case, export type InitObject = {};

Which (i think) makes it very clear (and forces?) you to return the first argument.

But it's not a generic function, surely adding a generic just overcomplicates things?

benjie commented

V5 changes the type to Record<string, never>, so I'm closing this.