(Can currently be worked around using as unknown as string on the array.)
Steps to Reproduce
Compile:
import fastify from 'fastify'
import nunjucks from 'nunjucks'
const server = fastify()
server.register(fastifyView, {
engine: {
nunjucks,
},
templates: [
'test',
'test2',
],
})
The following type error is returned:
error TS2769: No overload matches this call.
Overload 1 of 3, '(plugin: FastifyPluginCallback<PointOfViewOptions, RawServerDefault, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Type 'string[]' is not assignable to type 'string'.
Overload 2 of 3, '(plugin: FastifyPluginAsync<PointOfViewOptions, RawServerDefault, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'FastifyPluginCallback<PointOfViewOptions, RawServerDefault, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginAsync<PointOfViewOptions, RawServerDefault, FastifyTypeProviderDefault>'.
Overload 3 of 3, '(plugin: FastifyPluginCallback<PointOfViewOptions, RawServerDefault, FastifyTypeProviderDefault> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Type 'string[]' is not assignable to type 'string'.
Prerequisites
Fastify version
4.9.2
Plugin version
7.1.2
Node.js version
18.12.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
22.04
Description
As per the example for Nunjucks, an array of strings should be allowed for the
templates
option (at least for Nunjucks):https://github.com/fastify/point-of-view#nunjucks
However, it is currently typed as an optional
string
, so passing an array of strings is currently a type error:https://github.com/fastify/point-of-view/blob/2124f9e3ef0d771fbefd65aeecb94a8943b8d7df/types/index.d.ts#L33
(Can currently be worked around using
as unknown as string
on the array.)Steps to Reproduce
Compile:
The following type error is returned:
Expected Behavior
No type error.