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

Type 'HooksT' does not satisfy the constraint 'Record<string, any>' #62

Open
Vinccool96 opened this issue Dec 11, 2022 · 4 comments
Open

Comments

@Vinccool96
Copy link
Contributor

Environment

Node: 16.17.1
typescript: 4.9.4
hookable: 5.4.2

Reproduction

Minimal reproduction

Run yarn run build or tsc.

Describe the bug

A PR for this issue will be submitted

When compiling with tsc, everything gets compiled correctly, but we receive this error message:

node_modules/hookable/dist/index.d.ts:65:49 - error TS2344: Type 'HooksT' does not satisfy the constraint 'Record<string, any>'.

65     beforeEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
                                                   ~~~~~~

  node_modules/hookable/dist/index.d.ts:46:24
    46 declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {   
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends Record<string, any>` constraint.

node_modules/hookable/dist/index.d.ts:66:48 - error TS2344: Type 'HooksT' does not satisfy the constraint 'Record<string, any>'.

66     afterEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
                                                  ~~~~~~

  node_modules/hookable/dist/index.d.ts:46:24
    46 declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends Record<string, any>` constraint.


Found 2 errors in the same file, starting at: node_modules/hookable/dist/index.d.ts:65

error Command failed with exit code 2.

Additional context

No response

Logs

No response

@Vinccool96
Copy link
Contributor Author

@pi0 What do you think about that? It looks like it's a problem when TS is in strict mode

@Vinccool96
Copy link
Contributor Author

i created strict-hookable whille waiting for this to be resolved (NPM page)

@Vinccool96
Copy link
Contributor Author

Bump

KaelWD added a commit to vuetifyjs/vuetify that referenced this issue Feb 21, 2023
@abarke
Copy link
Contributor

abarke commented Feb 28, 2023

In my project it works in strict mode using:

import { Hookable, HookCallback, createHooks } from 'hookable';

export enum Hook {
  READY = 'ready',
}

export interface HookTypes extends Record<string, HookCallback> {
  [Hook.READY]: () => void;
}

const hooks = createHooks<HookTypes>();

hooks.addHooks({
  [Hook.READY]: async () => console.log('🔌', Hook.READY),
});

hooks.callHook(Hook.READY);

Stackblitz: https://hookable-typescript-strict.stackblitz.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants