[@types/caseless] Add Httpified interface. (#22935)

To allow importing libs to extend the interface.
Objects passed into `caseless.httpify` are extended with these methods.
This commit is contained in:
Matt R. Wilson
2018-01-17 09:44:51 -08:00
committed by Wesley Wigham
parent 71ca70ae88
commit cc668c2e38
2 changed files with 28 additions and 1 deletions
+18 -1
View File
@@ -1,4 +1,4 @@
import caseless, { Caseless, httpify } from "caseless";
import caseless, { Caseless, httpify, Httpified } from "caseless";
new Caseless(); // $ExpectError
@@ -38,3 +38,20 @@ httpify({}, 1); // $ExpectError
httpify({}, "2"); // $ExpectError
httpify({}, {}); // $ExpectType Caseless
const request: Httpified = {}; // $ExpectError
request.setHeader({}); // $ExpectType void
request.setHeader('foo', 'bar'); // $ExpectType string | false
request.setHeader('foo', 'bar', false); // $ExpectType string | false
request.setHeader('foo', new Date()); // $ExpectType string | false
request.setHeader(10, 'bar'); // $ExpectError
request.getHeader('foo'); // $ExpectType any
request.getHeader(10); // $ExpectError
request.hasHeader('foo'); // $ExpectType string | false
request.hasHeader(10); // $ExpectError
request.removeHeader('foo'); // $ExpectType boolean
request.headers = {};
+10
View File
@@ -1,6 +1,7 @@
// Type definitions for caseless 0.12
// Project: https://github.com/mikeal/caseless
// Definitions by: downace <https://github.com/downace>
// Matt R. Wilson <https://github.com/mastermatt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -17,6 +18,15 @@ export interface Caseless {
del(name: KeyType): boolean;
}
export interface Httpified {
headers: RawDict;
setHeader(name: KeyType, value: ValueType, clobber?: boolean): KeyType | false;
setHeader(dict: RawDict): void;
hasHeader(name: KeyType): KeyType | false;
getHeader(name: KeyType): ValueType | undefined;
removeHeader(name: KeyType): boolean;
}
export function httpify(resp: object, headers: RawDict): Caseless;
declare function caseless(dict?: RawDict): Caseless;