Merge pull request #22491 from downace/types-caseless

[@types/caseless] Add type definition for caseless version 0.12
This commit is contained in:
Paul van Brenk
2017-12-27 13:39:39 -08:00
committed by GitHub
4 changed files with 88 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import caseless, { Caseless, httpify } from "caseless";
new Caseless(); // $ExpectError
// tslint:disable-next-line: prefer-const
let c1: Caseless;
caseless(); // $ExpectType Caseless
caseless({}); // $ExpectType Caseless
caseless(null); // $ExpectError
caseless(1); // $ExpectError
caseless("2"); // $ExpectError
const c2 = caseless();
c2.set({}); // $ExpectType void
c2.set('foo', 'bar'); // $ExpectType string | false
c2.set('foo', 'bar', false); // $ExpectType string | false
c2.set('foo', new Date()); // $ExpectType string | false
c2.set(10, 'bar'); // $ExpectError
c2.get('foo'); // $ExpectType any
c2.get(10); // $ExpectError
c2.has('foo'); // $ExpectType string | false
c2.has(10); // $ExpectError
c2.swap('foo'); // $ExpectType void
c2.swap(10); // $ExpectError
c2.del('foo'); // $ExpectType boolean
httpify(null, {}); // $ExpectError
httpify(1, {}); // $ExpectError
httpify("2", {}); // $ExpectError
httpify({}, null); // $ExpectError
httpify({}, 1); // $ExpectError
httpify({}, "2"); // $ExpectError
httpify({}, {}); // $ExpectType Caseless
+24
View File
@@ -0,0 +1,24 @@
// Type definitions for caseless 0.12
// Project: https://github.com/mikeal/caseless
// Definitions by: downace <https://github.com/downace>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
type KeyType = string;
type ValueType = any;
type RawDict = object;
export interface Caseless {
set(name: KeyType, value: ValueType, clobber?: boolean): KeyType | false;
set(dict: RawDict): void;
has(name: KeyType): KeyType | false;
get(name: KeyType): ValueType | undefined;
swap(name: KeyType): void;
del(name: KeyType): boolean;
}
export function httpify(resp: object, headers: RawDict): Caseless;
declare function caseless(dict?: RawDict): Caseless;
export default caseless;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"caseless-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }