Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typedefs don't support propertyName #301

Open
2 tasks done
a-a-GiTHuB-a-a opened this issue Apr 3, 2022 · 8 comments
Open
2 tasks done

Typedefs don't support propertyName #301

a-a-GiTHuB-a-a opened this issue Apr 3, 2022 · 8 comments
Labels
bug Confirmed bug good first issue Good for newcomers

Comments

@a-a-GiTHuB-a-a
Copy link

a-a-GiTHuB-a-a commented Apr 3, 2022

Prerequisites

  • I have written a descriptive issue title
  • 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.

@mcollina
Copy link
Member

mcollina commented Apr 4, 2022

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

@mcollina mcollina added bug Confirmed bug good first issue Good for newcomers labels Apr 4, 2022
@a-a-GiTHuB-a-a
Copy link
Author

I can try...

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 12, 2022

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

@eiskalteschatten
Copy link

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

@Uzlopak
Copy link
Contributor

Uzlopak commented Jan 4, 2023

Did you read my post?

@eiskalteschatten
Copy link

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.

@lord007tn
Copy link

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

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

@Uzlopak
Copy link
Contributor

Uzlopak commented May 14, 2023

@lord007tn ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants