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

Provide typescript type definitions #220

Open
Sytten opened this issue Nov 25, 2021 · 2 comments
Open

Provide typescript type definitions #220

Sytten opened this issue Nov 25, 2021 · 2 comments

Comments

@Sytten
Copy link

Sytten commented Nov 25, 2021

Hi!
It would be nice if you could provide a .d.ts file for typescript folks like me :)
Thanks

@Sytten
Copy link
Author

Sytten commented Nov 26, 2021

I did a first pass:

declare module 'prerender-node' {
  import { NextFunction, Request, Response } from 'express';

  declare function prerender(
    req: Request,
    res: Response,
    next: NextFunction
  ): void;

  declare namespace prerender {
    type Done = (page?: { status: number; body: string | Buffer }) => void;
    type Set = {
      prerenderToken: string;
      beforeRender: (req: Request, done: Done) => void;
      afterRender: (err: any, req: Request, prerenderRes: any) => void;
      protocol: 'http' | 'https';
      host: string;
      forwardHeaders: boolean;
      prerenderServerRequestOptions: Record<string, any>;
    };
    declare function set<T extends keyof Set>(
      name: T,
      value: Set[T]
    ): typeof prerender;

    declare function whitelisted(
      whitelist: string | string[]
    ): typeof prerender;
    declare function blacklisted(
      blacklist: string | string[]
    ): typeof prerender;
  }

  export = prerender;
}

@gzurbach
Copy link

gzurbach commented Jul 4, 2023

@Sytten thanks for providing these definitions 👍

Just a small correction:

type Done = (err?: Error | null, page?: { status?: number; body?: string | Buffer }) => void;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants