Skip to content

Commit

Permalink
Type of templates property in PointOfViewOptions show allow arrays (#359
Browse files Browse the repository at this point in the history
)

* fix: updated templates type to string or string[] closes #352

* fix: added tests for templates string and string[]
  • Loading branch information
dancastillo authored Jan 13, 2023
1 parent 7564b67 commit 134ff28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare namespace fastifyView {
liquid?: any;
dot?: any;
};
templates?: string;
templates?: string | string[];
includeViewExtension?: boolean;
options?: object;
charset?: string;
Expand Down
22 changes: 22 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,25 @@ expectType<Promise<string>>(app.view("/index", {}, { layout: "/layout-ts"}))
expectAssignable<FastifyViewOptions>({ engine: { twig: require('twig') }, propertyName: 'mobile' })

expectDeprecated({} as PointOfViewOptions)

const nunjucksApp = fastify()

nunjucksApp.register(fastifyView, {
engine: {
nunjucks: require('nunjucks'),
},
templates: [
'templates/nunjucks-layout',
'templates/nunjucks-template'
],
})

nunjucksApp.get('/', (request, reply) => {
reply.view('index.njk', { text: 'Sample data' })
})

expectType<Promise<string>>(nunjucksApp.view('/', { text: 'Hello world' }))

expectAssignable<FastifyViewOptions>({ engine: { nunjucks: require('nunjucks') }, templates: 'templates' })

expectAssignable<FastifyViewOptions>({ engine: { nunjucks: require('nunjucks') }, templates: ['templates/nunjucks-layout', 'templates/nunjucks-template']})

0 comments on commit 134ff28

Please sign in to comment.