Skip to content

Instantly share code, notes, and snippets.

@frzi
Last active September 19, 2019 19:56
Show Gist options
  • Save frzi/a1bc8e2064bf1022c48151afd91aeb2f to your computer and use it in GitHub Desktop.
Save frzi/a1bc8e2064bf1022c48151afd91aeb2f to your computer and use it in GitHub Desktop.
Polka Typescript definitions
/**
* Potential candidate for @types/polka.
*/
// Type definitions for polka 1.0.0
// Project: https://github.com/lukeed/polka
// Definitions by: Freek Zijlmans <https://github.com/frzi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types="node" />
/// <reference types="trouter" />
import { IncomingMessage, ServerResponse } from 'http';
import { Server } from 'net'
import Trouter from 'trouter';
declare function polka(options?: polka.Options): polka.Polka;
declare namespace polka {
type NextHandler = (err?: Error | string) => void;
type RequestHandler = (req: IncomingMessage, res: ServerResponse, next?: NextHandler) => void;
type Middleware = Polka | RequestHandler;
type ErrorHandler = (err: Error | string, req: IncomingMessage, res: ServerResponse, next: NextHandler) => void;
interface Options {
onError?: ErrorHandler;
onNoMatch?: RequestHandler;
server?: typeof Server;
}
interface URLDescription {
_raw: string;
href: string;
path: string;
pathname: string;
query: string | null;
search: string | null;
}
interface Polka extends Trouter<RequestHandler> {
readonly server: typeof Server;
readonly wares: RequestHandler[];
readonly onError: ErrorHandler;
readonly onNoMatch: RequestHandler;
attach: (req: IncomingMessage, res: ServerResponse) => void;
parse: (req: IncomingMessage) => URLDescription | void;
use(...handlers: Middleware[]): this;
use(pattern: string, ...handlers: Middleware[]): this;
readonly handler: RequestHandler
listen: Server['listen'];
}
}
export = polka;
@lukeed
Copy link

lukeed commented May 2, 2019

Hey hey 👋

Checking in to let you know that wares has been removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment