point-of-view icon indicating copy to clipboard operation
point-of-view copied to clipboard

Typedefs don't support `propertyName`

Open a-a-GiTHuB-a-a opened this issue 2 years ago • 8 comments

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.

a-a-GiTHuB-a-a avatar Apr 03 '22 21:04 a-a-GiTHuB-a-a

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Apr 04 '22 17:04 mcollina

I can try...

a-a-GiTHuB-a-a avatar Apr 05 '22 16:04 a-a-GiTHuB-a-a

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;
  }
}

Uzlopak avatar Sep 12 '22 09:09 Uzlopak

Has anyone attempted this yet? I'm running my head into the wall trying to get this to work...

eiskalteschatten avatar Jan 04 '23 22:01 eiskalteschatten

Did you read my post?

Uzlopak avatar Jan 04 '23 22:01 Uzlopak

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.

eiskalteschatten avatar Jan 04 '23 22:01 eiskalteschatten

what do you think about changing the plugin definition and logic to something like

reply.render("propertyName", "/templates/index.ejs", { text: "text" });

lord007tn avatar Apr 20 '23 04:04 lord007tn

@lord007tn ?

Uzlopak avatar May 14 '23 21:05 Uzlopak