From 63477193daa94bc3eba07b88e688a64735d96891 Mon Sep 17 00:00:00 2001 From: Claas Ahlrichs Date: Thu, 2 May 2019 01:00:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=A3=F0=9F=90=87=F0=9F=90=A3=20new=20pa?= =?UTF-8?q?ckage:=20kind-of=20=F0=9F=8E=85=20(#34879)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * npx dts-gen -m kind-of --dt * drafted types for kind-of * reordered overloads * added more overloads * fixed linting issues * npx prettier --write .\types\kind-of\** * updated teste cases * clarified edge-cases * work around banned types --- types/kind-of/index.d.ts | 48 +++++++++++++++++++++++++++ types/kind-of/kind-of-tests.ts | 59 ++++++++++++++++++++++++++++++++++ types/kind-of/tsconfig.json | 17 ++++++++++ types/kind-of/tslint.json | 1 + 4 files changed, 125 insertions(+) create mode 100644 types/kind-of/index.d.ts create mode 100644 types/kind-of/kind-of-tests.ts create mode 100644 types/kind-of/tsconfig.json create mode 100644 types/kind-of/tslint.json diff --git a/types/kind-of/index.d.ts b/types/kind-of/index.d.ts new file mode 100644 index 0000000000..89990c2505 --- /dev/null +++ b/types/kind-of/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for kind-of 6.0 +// Project: https://github.com/jonschlinkert/kind-of +// Definitions by: Claas Ahlrichs +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.7 +/// + +export = kind_of; + +declare function kind_of(thing: undefined): "undefined"; +declare function kind_of(thing: null): "null"; +declare function kind_of(thing: boolean): "boolean"; +declare function kind_of(thing: Buffer): "buffer"; +declare function kind_of(thing: number): "number"; +declare function kind_of(thing: string): "string"; +declare function kind_of(thing: typeof arguments): "arguments"; +declare function kind_of(thing: Date): "date"; +declare function kind_of(thing: any[]): "array"; +declare function kind_of(thing: RegExp): "regexp"; +declare function kind_of(thing: Error): "error"; +declare function kind_of( + thing: Iterator +): + | "generator" + | "stringiterator" + | "arrayiterator" + | "mapiterator" + | "setiterator"; +declare function kind_of( + thing: (...args: any[]) => any +): "function" | "generatorfunction"; +declare function kind_of(thing: symbol): "symbol"; +declare function kind_of(thing: Promise): "promise"; +declare function kind_of(thing: Map): "map"; +declare function kind_of(thing: WeakMap): "weakmap"; +declare function kind_of(thing: Set): "set"; +declare function kind_of(thing: WeakSet): "weakset"; +declare function kind_of(thing: Int8Array): "int8array"; +declare function kind_of(thing: Uint8Array): "uint8array"; +declare function kind_of(thing: Uint8ClampedArray): "uint8clampedarray"; +declare function kind_of(thing: Int16Array): "int16array"; +declare function kind_of(thing: Uint16Array): "uint16array"; +declare function kind_of(thing: Int32Array): "int32array"; +declare function kind_of(thing: Uint32Array): "uint32array"; +declare function kind_of(thing: Float32Array): "float32array"; +declare function kind_of(thing: Float64Array): "float64array"; +declare function kind_of(thing: any): string; diff --git a/types/kind-of/kind-of-tests.ts b/types/kind-of/kind-of-tests.ts new file mode 100644 index 0000000000..c9fa028e28 --- /dev/null +++ b/types/kind-of/kind-of-tests.ts @@ -0,0 +1,59 @@ +import kindOf from "kind-of"; + +function sampleFunction() { + kindOf(arguments); + // => 'arguments' +} + +function* sampleGeneratorFunction() { + yield true; +} + +kindOf(undefined) === 'undefined'; +kindOf(null) === 'null'; +kindOf(true) === 'boolean'; +kindOf(false) === 'boolean'; +kindOf(Buffer.alloc(42)) === 'buffer'; +kindOf(42) === 'number'; +kindOf(Number.prototype) === 'number'; +kindOf("str") === 'string'; +kindOf(String.prototype) === 'string'; +kindOf(`${42 - 23}`) === 'string'; +kindOf({}) === 'object'; +kindOf(Object.create(null)) === 'object'; +kindOf(Object.prototype) === 'object'; +kindOf(new class Test {}()) === 'object'; +kindOf(new Date()) === 'date'; +kindOf([1, 2, 3]) === 'array'; +kindOf(/foo/) === 'regexp'; +kindOf(new RegExp("foo")) === 'regexp'; +kindOf(new Error("error")) === 'error'; +kindOf(() => {}) === 'function'; +kindOf(sampleFunction) === 'function'; +kindOf(sampleGeneratorFunction) === 'generatorfunction'; +kindOf(function*(): IterableIterator {}) === 'generatorfunction'; +kindOf(sampleGeneratorFunction()) === 'generator'; +kindOf(new Map()[Symbol.iterator]()) === 'mapiterator'; +kindOf(new Map().values()) === 'mapiterator'; +kindOf(new Set()[Symbol.iterator]()) === 'setiterator'; +kindOf(new Set().values()) === 'setiterator'; +kindOf("text"[Symbol.iterator]()) === 'stringiterator'; +kindOf([][Symbol.iterator]()) === 'arrayiterator'; +kindOf([].entries()) === 'arrayiterator'; +kindOf(Symbol("str")) === 'symbol'; +kindOf(Symbol.prototype) === 'symbol'; +kindOf(Promise.resolve(123)) === 'promise'; +kindOf(Promise.reject(new Error("foo bar")).catch(() => {})) === 'promise'; +kindOf(new Map()) === 'map'; +kindOf(new WeakMap()) === 'weakmap'; +kindOf(new Set()) === 'set'; +kindOf(new WeakSet()) === 'weakset'; +kindOf(Int8Array.of(0)) === 'int8array'; +kindOf(Uint8Array.of(0)) === 'uint8array'; +kindOf(Uint8ClampedArray.of(0)) === 'uint8clampedarray'; +kindOf(Int16Array.of(0)) === 'int16array'; +kindOf(Uint16Array.of(0)) === 'uint16array'; +kindOf(Int32Array.of(0)) === 'int32array'; +kindOf(Uint32Array.of(0)) === 'uint32array'; +kindOf(Float32Array.of(0)) === 'float32array'; +kindOf(Float64Array.of(0)) === 'float64array'; diff --git a/types/kind-of/tsconfig.json b/types/kind-of/tsconfig.json new file mode 100644 index 0000000000..b25d2f56c3 --- /dev/null +++ b/types/kind-of/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": ["index.d.ts", "kind-of-tests.ts"] +} diff --git a/types/kind-of/tslint.json b/types/kind-of/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/kind-of/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }