graphile-engine icon indicating copy to clipboard operation
graphile-engine copied to clipboard

InitObject is typed wrong

Open husseinhere opened this issue 3 years ago • 3 comments

I think: https://github.com/graphile/graphile-engine/blob/1bc8cfefdab7a61fd7ad287bcdff66298352e308/packages/graphile-build/src/SchemaBuilder.d.ts#L40

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)

husseinhere avatar Feb 10 '22 05:02 husseinhere

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

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

benjie avatar Feb 10 '22 08:02 benjie

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.

husseinhere avatar Feb 10 '22 19:02 husseinhere

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

benjie avatar Mar 07 '22 10:03 benjie

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

benjie avatar Sep 27 '23 16:09 benjie