add type definitions for bidirectional-map (#25459)

This commit is contained in:
Helen Anderson 2018-05-03 09:10:13 -07:00 committed by Andy
parent d6da19d371
commit d79f176a3a
4 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import BiMap from "bidirectional-map";
const bidirectionalMap = new BiMap({
one: 1
});
bidirectionalMap.size; // $ExpectType number
bidirectionalMap.set("two", 2);
bidirectionalMap.set("three", 3);
bidirectionalMap.get("one"); // $ExpectType number
bidirectionalMap.get(true); // $ExpectError
bidirectionalMap.getKey(1); // $ExpectType string
bidirectionalMap.getKey("one"); // $ExpectError
bidirectionalMap.delete("two");
bidirectionalMap.deleteValue(3);
bidirectionalMap.entries(); // $ExpectType IterableIterator<[string, number]>
bidirectionalMap.has("one"); // $ExpectType boolean
bidirectionalMap.hasValue(2); // $ExpectType boolean
bidirectionalMap.keys(); // $ExpectType IterableIterator<string>
bidirectionalMap.values(); // $ExpectType IterableIterator<number>

22
types/bidirectional-map/index.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
// Type definitions for bidirectional-map 1.0
// Project: https://github.com/educastellano/bidirectional-map
// Definitions by: Helen Anderson <https://github.com/helenanderson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export default class BiMap<TValue> {
constructor(object?: { [i: string]: TValue });
size: number;
set(key: string, value: TValue): void;
get(key: string): TValue;
getKey(value: TValue): string;
clear(): void;
delete(key: string): void;
deleteValue(value: TValue): void;
entries(): IterableIterator<[string, TValue]>;
has(key: string): boolean;
hasValue(value: TValue): boolean;
keys(): IterableIterator<string>;
values(): IterableIterator<TValue>;
}

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",
"bidirectional-map-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }