point-of-view
point-of-view copied to clipboard
Typedefs don't support `propertyName`
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
N/A
Plugin version
N/A
Node.js version
N/A
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
N/A
Description
In the index.d.ts
file, I noticed that they extend the FastifyReply
type for view
, which doesn't take into account other property names (eg. I might choose render
instead).
Steps to Reproduce
N/A
Expected Behavior
The d.ts
file should somehow account for custom property names.
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
I can try...
I think the only thing what we can do is to export something like
interface PointOfViewRouteSpecificOptions {
layout?: string;
}
export type PointOfViewProperty<K extends string = 'view', T extends { [key: string]: any } = { [key: string]: any }, R = Promise<string>> =
Record<K, (page: string, data: T, opts?: PointOfViewRouteSpecificOptions) => R>
And you have then to do in your own Project:
declare module "fastify" {
interface RouteSpecificOptions extends
PointOfViewRouteSpecificOptions { }
interface FastifyReply extends
PointOfViewProperty<'render', object, FastifyReply>{
view: never;
}
interface FastifyInstance extends
PointOfViewProperty<'render', object, Promise<string>>{ {
view: never;
}
}
Has anyone attempted this yet? I'm running my head into the wall trying to get this to work...
Did you read my post?
I did. I haven't attempted to change anything in @fastify/point-of-view
yet though. What I meant is that I was bashing my head against a wall trying to get it to work in my own project.
If no one has attempted to get it to work, maybe I'll fork it and give it a shot tomorrow. That's why I was asking.
what do you think about changing the plugin definition and logic to something like
reply.render("propertyName", "/templates/index.ejs", { text: "text" });
@lord007tn ?