@types/cors

TypeScript definitions for cors

  • Types
  • ESM
  • CJS
License
MIT
Install Size
6.1 kB(2.5 MB)
Vulns
0
Published

Get started

$npm install @types/cors
$pnpm add @types/cors
$yarn add @types/cors
$bun add @types/cors
$deno add npm:@types/cors
$vlt install @types/cors
$vp add @types/cors
# Usually installed as a dev dependency
$npm install -D @types/cors
$pnpm add -D @types/cors
$yarn add -D @types/cors
$bun add -d @types/cors
$deno add -D npm:@types/cors
$vlt install -D @types/cors
$vp add -D @types/cors

Weekly DownloadsAcross all versions

Versions

View all versions
2.8.19
latestts5.1ts5.2ts5.3ts5.4ts5.5ts5.6ts5.7ts5.8ts5.9ts6.0
2.8.17
ts4.5ts4.6ts4.7ts4.8ts4.9ts5.0
2.8.14
ts4.3ts4.4
2.8.13
ts4.2
2.8.12
ts3.6ts3.7ts3.8ts3.9ts4.0ts4.1
2.8.10
ts3.4ts3.5
2.8.9
ts3.3
2.8.8
ts3.2
2.8.7
ts3.0ts3.1
2.8.6
ts2.3ts2.4ts2.5ts2.6ts2.7ts2.8ts2.9

Readme

Installation

npm install --save @types/cors

Summary

This package contains type definitions for cors (https://github.com/expressjs/cors/).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors.

index.d.ts

/// <reference types="node" />

import { IncomingHttpHeaders } from "http";

type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>;

type CustomOrigin = (
    requestOrigin: string | undefined,
    callback: (err: Error | null, origin?: StaticOrigin) => void,
) => void;

declare namespace e {
    interface CorsRequest {
        method?: string | undefined;
        headers: IncomingHttpHeaders;
    }
    interface CorsOptions {
        /**
         * @default '*'
         */
        origin?: StaticOrigin | CustomOrigin | undefined;
        /**
         * @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
         */
        methods?: string | string[] | undefined;
        allowedHeaders?: string | string[] | undefined;
        exposedHeaders?: string | string[] | undefined;
        credentials?: boolean | undefined;
        maxAge?: number | undefined;
        /**
         * @default false
         */
        preflightContinue?: boolean | undefined;
        /**
         * @default 204
         */
        optionsSuccessStatus?: number | undefined;
    }
    type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
        req: T,
        callback: (err: Error | null, options?: CorsOptions) => void,
    ) => void;
}

declare function e<T extends e.CorsRequest = e.CorsRequest>(
    options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
): (
    req: T,
    res: {
        statusCode?: number | undefined;
        setHeader(key: string, value: string): any;
        end(): any;
    },
    next: (err?: any) => any,
) => void;
export = e;
Additional Details
  • Last updated: Sat, 07 Jun 2025 02:15:25 GMT
  • Dependencies: @types/node

Credits

These definitions were written by Alan Plum, Gaurav Sharma, and Sebastian Beltran.