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

InitObject is typed wrong #778

Closed
husseinhere opened this issue Feb 10, 2022 · 4 comments
Closed

InitObject is typed wrong #778

husseinhere opened this issue Feb 10, 2022 · 4 comments

Comments

@husseinhere
Copy link

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)

@benjie
Copy link
Member

benjie commented Feb 10, 2022

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

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

@husseinhere
Copy link
Author

husseinhere commented Feb 10, 2022

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.

@benjie
Copy link
Member

benjie commented Mar 7, 2022

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

@benjie
Copy link
Member

benjie commented Sep 27, 2023

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

@benjie benjie closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants