Add typings for just-pick (#30605)

This commit is contained in:
Peter Safranek
2018-11-18 13:41:20 -08:00
committed by Pranav Senthilnathan
parent 0ce9dbee58
commit ea65f55484
4 changed files with 66 additions and 0 deletions

11
types/just-pick/index.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
// Type definitions for just-pick 2.1
// Project: https://github.com/angus-c/just#readme
// Definitions by: Peter Safranek <https://github.com/pe8ter>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
declare function pick<T, U extends keyof T>(obj: T, select: U[]): Pick<T, U>;
declare function pick<T, U extends keyof T>(obj: T, select1: U, ...selectn: U[]): Pick<T, U>;
export = pick;

View File

@@ -0,0 +1,26 @@
import pick = require("just-pick");
const a = "a";
const b = "b";
const c = "c";
const obj = { a, b };
pick(obj, []); // $ExpectType Pick<{ a: string; b: string; }, never>
pick(obj, [a]); // $ExpectType Pick<{ a: string; b: string; }, "a">
pick(obj, [a, a]); // $ExpectType Pick<{ a: string; b: string; }, "a">
pick(obj, [a, b]); // $ExpectType Pick<{ a: string; b: string; }, "a" | "b">
pick(obj, [a, b, c]); // $ExpectError
pick(obj, a); // $ExpectType Pick<{ a: string; b: string; }, "a">
pick(obj, a, a); // $ExpectType Pick<{ a: string; b: string; }, "a">
pick(obj, a, b); // $ExpectType Pick<{ a: string; b: string; }, "a" | "b">
pick(obj, a, b, c); // $ExpectError
pick(); // $ExpectError
pick(obj); // $ExpectError
pick(obj, 0); // $ExpectError
pick(obj, false); // $ExpectError
pick(obj, null); // $ExpectError
pick(obj, undefined); // $ExpectError
pick(obj, {}); // $ExpectError
pick(obj, () => {}); // $ExpectError

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",
"just-pick-tests.ts"
]
}

View File

@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"file-name-casing": false
}
}