[@types/map-to-obj] New type definition (#37638)

* [@types/map-to-obj] New type definition

* [@types/map-to-obj] Fixed typo
This commit is contained in:
Kwok Chi Leong
2019-08-16 05:27:22 +08:00
committed by Pranav Senthilnathan
parent c38b215bfb
commit b489356bba
4 changed files with 57 additions and 0 deletions

13
types/map-to-obj/index.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
// Type definitions for map-to-obj 0.2
// Project: https://github.com/egoist/map-to-obj#readme
// Definitions by: Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
/**
* Convert a `Map` instance into a plain `object`.
* @param map The target to be converted
*/
declare function MapToObj<K extends string | number | symbol, V>(map: Map<K, V>): Record<K, V>;
export = MapToObj;

View File

@@ -0,0 +1,18 @@
'use strict';
import MapToObj from 'map-to-obj';
// $ExpectType Record<any, any>
MapToObj(new Map());
// $ExpectType Record<string, string>
MapToObj(new Map([['hello', 'world']]));
// $ExpectType Record<number, number>
MapToObj(new Map([[0, 1]]));
// $ExpectType Record<symbol, symbol>
MapToObj(new Map([[Symbol('hello'), Symbol('world')]]));
// $ExpectError
MapToObj(new Map([[{}, {}]]));

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"map-to-obj-tests.ts"
]
}

View File

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