Typescript: broken register with plugin array
- Dominant language
- JavaScript
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 22d 3h
- Merged PRs (30d)
- 1
Description
#### 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.
```js
import { Server, Plugin } from '@hapi/hapi';
interface TestPluginOptions {
x: number;
}
interface TestPluginDecorations {
plugins: {
test: {
add(a: number, b: number): number;
};
}
}
const plugin1: Plugin = {
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 = {
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](https://ts-error-translator.vercel.app/?error=HIewBCBuCmBOA2ICGATMBbJAXAxgC2gGcws8BLYnJeeAOgCgwwAVAseJQrCGBZNAOZIYJNgDMQNEAHcyAOwFg4sELAZMmzAJ4AHaGADkABXgBXAfIA8zIlhPn5AeR1YyIOYQA0LW-YtyAEWgcVWw3DwA+AzAKMDkQbk5CMgE5JAAjeH0scCxdfWMzf0sAbzAADwAuONN0dLgAbjAAXzAAHzAy8oB+atM5FGgxeWgUJubvSBAyFAj2zrAdIvlqvysu6rla+thx+a7esH7B4blR8cnp2fGDdQ1NfMM1uQAhTmhrX2W5Z1d3Lx8XGeQRCsDC-zmADIwM9gEh0NAAGpwZLuaKxeKJQjJVIZLIkXKPQoOOSlCqbbaNFr7CqHY5DEZjFqXGZzDplJYk1bfMlVGp1Kmtdm0voDBlnJkTMBTVk3O73B56J7fN6ED42IHfX7hAEauzfEGhP6RMDQ2HwpEo8Lo4iYsBJFJpTLZQlK4n+VUfDb8nZ7YU9UUnRkXaVXKEw75whHI2CouS3RgK+7aN3PT2fTUk7X-bx64HBI068Pm6NWtExW0Je3Yx14l0kIlp968ikC3bU-10sWnc7M0OshNJpMpogQMSLFR6WB5QwAfXnABI8npZyAxLPOf5Z4NQeCPAv57PokhYPp5CF0Dows75UPk0S8waC2DjYQbXEqw7cc6CQ23TKUEHO8hxHZUSUsACogrD8sRxJ18RyP8CmeFsfUFGkAyObtgz7SCaU3FYI3A70tjbP0Fkw+ke0lFlrhaIDgJAxsVWbADaOLSMLRjON3ztL94PrZdkJ5EjKXbIUKK7IMJRDPDhQIuRuWI8k0PEjCpPFXspUguVE0Yu9QPdeR0zY-tZlNIj-CjS1Y2taC+Jrb8ENdYSSXTUSyI7STA00mizI4klrO461b30pjUxYtUIKudiLJLGyePsz9HIE38hLAj1mw830vIOHzqNksMGLC4CR2INcJxAKcZwMU8LC4OBj1PGI5AvK9XBvPSSsYwyAAo1VgXhqgAZTgXhLFGwa4AAQR0JYyCoY1hqwbBoAibwqtfaoAIASjAABeOYAPmIwVHQCgPkg3jkrgus0qJfqxrgEantgCbXtm+bFvCZbVvWiAXB1apsvQzt8pw5o9sOsyTrOi7ooHULutK-JyvHK8wQRLAUUMTadWPAZccB-4mrPVqQEva8siR5GUbdEG1LBrDpK067YNrH9EPSgwAOK2mwsMhmbiS9mnMEoledoIA)
#### What result did you expect?
It should work with `tsc index.ts`
Contributor guide
Assessment
This issue has not been assessed yet.