0

I'am new to typescript and trying to fix index.d.ts typescript declaration file for fastify-static plugin

index.d.ts looks like this:

import fastify = require("fastify");

import { Server, IncomingMessage, ServerResponse } from "http";
import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from "http2"

declare module "fastify" {
    interface FastifyReply<HttpResponse> {
        sendFile(filename: string): FastifyReply<HttpResponse>;
    }
}

declare const fastifyStatic: fastify.Plugin<Server, IncomingMessage, ServerResponse , {
    root: string;
    prefix?: string;
    serve?: boolean;
    decorateReply?: boolean;
    schemaHide?: boolean;
    setHeaders?: (...args: any[]) => void;
    redirect?: boolean;
    wildcard?: boolean | string;

    // Passed on to `send`
    acceptRanges?: boolean;
    cacheControl?: boolean;
    dotfiles?: boolean;
    etag?: boolean;
    extensions?: string[];
    immutable?: boolean;
    index?: string[];
    lastModified?: boolean;
    maxAge?: string | number;
}>;

export = fastifyStatic;

I need to change this declaration file so const fastifyStatic will accept interfaces

Server, IncomingMessage, ServerResponse

or

Http2SecureServer, Http2ServerRequest, Http2ServerResponse

Problem is that i can't really understand syntaxis of datatype:

fastify.Plugin<Interface, Interface, {}>

I would appreciate explanation of this or some documentation link.

1 Answer 1

1

That is the syntax for Generics.

In this case, it looks like you are providing typings for up to 4 things that fastify.Plugin would use internally or expose in its own type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.