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

Typescript: broken register with plugin array #4448

Open
Eomm opened this issue Apr 20, 2023 · 0 comments
Open

Typescript: broken register with plugin array #4448

Eomm opened this issue Apr 20, 2023 · 0 comments
Labels
support Questions, discussions, and general support

Comments

@Eomm
Copy link

Eomm commented Apr 20, 2023

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 18.x
  • module version with issue: 21.3.1
  • last module version without issue: -
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: typescript 4.9.5

What are you trying to achieve or the steps to reproduce?

By using server.register(pluginArray), typescript does not work.
Registering the same plugins one by one, it works.

import { Server, Plugin } from '@hapi/hapi';

interface TestPluginOptions {
  x: number;
}

interface TestPluginDecorations {
  plugins: {
    test: {
      add(a: number, b: number): number;
    };
  }
}

const plugin1: Plugin<TestPluginOptions, TestPluginDecorations> = {
  name: 'test',
  version: '1.0.0',
  register: function (srv, options) { }
};

const plugin2: Plugin<{}> = {
  name: 'tes2',
  version: '1.0.0',
  register: function (srvs, options) { }
};

const plugin3: Plugin<void> = {
  name: 'tes2',
  version: '1.0.0',
  register: function (srvs, options) { }
};

async function test() {
  const server = new Server();

  // does not work
  await server.register([
    { plugin: plugin1, options: { x: 1 } },
    { plugin: plugin2, options: {} },
    { plugin: plugin3, options: undefined },
  ]);

  // works
  await server.register({ plugin: plugin1, options: { x: 1 } });
  await server.register({ plugin: plugin2, options: {} });
  await server.register({ plugin: plugin3, options: undefined });
}

test()

What was the result you got?

Type '{ x: number; }' is not assignable to type 'void'.

Error:

Full stack

What result did you expect?

It should work with tsc index.ts

@Eomm Eomm added the support Questions, discussions, and general support label Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant