Add just-map-values and just-safe-set types (#42739)

* Add some just functions

* Fix some tests

* Fixes for code review

* Fix tests
This commit is contained in:
Andrew Casey
2020-03-04 16:12:34 -08:00
committed by GitHub
parent df8a7d9356
commit b6ded2b97e
8 changed files with 97 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
// Type definitions for just-map-values 1.1
// Project: https://github.com/angus-c/just#readme
// Definitions by: Roman Lerchster <https://github.com/wa4-fearless-otter>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function map<T extends {}>(item: T, callback: (value: any, key: string, object: T) => any): {};
export = map;
@@ -0,0 +1,11 @@
import map = require("just-map-values");
const obj = {foo: {bar: []}};
map(obj, (value) => value); // $ExpectType {}
map(obj, (value, key, object) => ''); // $ExpectType {}
// Incorrect argument
map(); // $ExpectError
map(obj); // $ExpectError
map(obj, ''); // $ExpectError
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"just-map-values-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+8
View File
@@ -0,0 +1,8 @@
// Type definitions for just-safe-set 2.1
// Project: https://github.com/angus-c/just#readme
// Definitions by: Roman Lerchster <https://github.com/wa4-fearless-otter>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function set(item: any[] | {}, target: string | symbol | Array<string | symbol>, value: any): boolean;
export = set;
@@ -0,0 +1,22 @@
import set = require("just-safe-set");
const arr = ['one', 'two'];
const obj = {foo: {bar: arr}};
// Pass single `object`.
set(arr, '0', {}); // $ExpectType boolean
set(arr, ['0'], ''); // $ExpectType boolean
set(obj, 'foo.bar', 0); // $ExpectType boolean
set(obj, 'foo.bar.0', 1); // $ExpectType boolean
// Incorrect argument
set(); // $ExpectError
set(obj); // $ExpectError
set([]); // $ExpectError
set({}); // $ExpectError
set(obj, 3); // $ExpectError
set(obj, [3]); // $ExpectError
set(false); // $ExpectError
set(null); // $ExpectError
set(undefined); // $ExpectError
set(obj, 'foo.bar'); // $ExpectError
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"just-safe-set-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }