From 17a24edb012e06c05dac9158b7d5266df667ef95 Mon Sep 17 00:00:00 2001 From: antoinebrault Date: Tue, 12 Feb 2019 17:06:30 -0500 Subject: [PATCH 01/11] [jest] add mock result type --- types/jest/index.d.ts | 31 ++++++++++++++++++++----------- types/jest/jest-tests.ts | 13 +++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 526beb2dc7..a09263369e 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -976,20 +976,29 @@ declare namespace jest { } /** - * Represents the result of a single call to a mock function. + * Represents the result of a single call to a mock function with a return value. */ - interface MockResult { - /** - * True if the function threw. - * False if the function returned. - */ - isThrow: boolean; - /** - * The value that was either thrown or returned by the function. - */ + interface MockResultReturn { + type: 'return'; + value: T; + } + /** + * Represents the result of a single incomplete call to a mock function. + */ + interface MockResultIncomplete { + type: 'incomplete'; + value: undefined; + } + /** + * Represents the result of a single call to a mock function with a thrown error. + */ + interface MockResultThrow { + type: 'throw'; value: any; } + type MockResult = MockResultReturn | MockResultThrow | MockResultIncomplete; + interface MockContext { calls: Y[]; instances: T[]; @@ -997,7 +1006,7 @@ declare namespace jest { /** * List of results of calls to the mock function. */ - results: MockResult[]; + results: Array>; } } diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index c643ca6a57..3ac82cda9d 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -480,6 +480,19 @@ mocked.test4.mockRejectedValue(new Error()); // $ExpectError mocked.test4.mockRejectedValueOnce(new Error()); +const mockResult = jest.fn(() => 1).mock.results[0]; +switch (mockResult.type) { + case 'return': + mockResult.value; // $ExpectType number + break; + case 'incomplete': + mockResult.value; // $ExpectType undefined + break; + case 'throw': + mockResult.value; // $ExpectType any + break; +} + /* Snapshot serialization */ const snapshotSerializerPlugin: jest.SnapshotSerializerPlugin = { From 13b42bcfd8673e3af44c70713cd82ca3ee41b553 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 31 Jan 2019 15:03:11 +0100 Subject: [PATCH 02/11] [react-dom] Allow maybe instance in findDOMNode --- types/react-dom/index.d.ts | 2 +- types/react-dom/react-dom-tests.tsx | 2 ++ types/react-dom/v15/index.d.ts | 2 +- types/react-dom/v15/react-dom-tests.ts | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/react-dom/index.d.ts b/types/react-dom/index.d.ts index f81bbf4021..19c842f5a2 100644 --- a/types/react-dom/index.d.ts +++ b/types/react-dom/index.d.ts @@ -17,7 +17,7 @@ import { DOMAttributes, DOMElement, ReactNode, ReactPortal } from 'react'; -export function findDOMNode(instance: ReactInstance): Element | null | Text; +export function findDOMNode(instance: ReactInstance | null | undefined): Element | null | Text; export function unmountComponentAtNode(container: Element): boolean; export function createPortal(children: ReactNode, container: Element, key?: null | string): ReactPortal; diff --git a/types/react-dom/react-dom-tests.tsx b/types/react-dom/react-dom-tests.tsx index 46274e3ffd..20bfda53ea 100644 --- a/types/react-dom/react-dom-tests.tsx +++ b/types/react-dom/react-dom-tests.tsx @@ -30,6 +30,8 @@ describe('ReactDOM', () => { const rootElement = document.createElement('div'); ReactDOM.render(React.createElement('div'), rootElement); ReactDOM.findDOMNode(rootElement); + ReactDOM.findDOMNode(null); + ReactDOM.findDOMNode(undefined); }); it('createPortal', () => { diff --git a/types/react-dom/v15/index.d.ts b/types/react-dom/v15/index.d.ts index 8a22fd9bc2..653469b277 100644 --- a/types/react-dom/v15/index.d.ts +++ b/types/react-dom/v15/index.d.ts @@ -15,7 +15,7 @@ import { DOMAttributes, DOMElement } from 'react'; -export function findDOMNode(instance: ReactInstance): E; +export function findDOMNode(instance: ReactInstance | null | undefined): E; export function findDOMNode(instance: ReactInstance): Element; export function render

, T extends Element>( diff --git a/types/react-dom/v15/react-dom-tests.ts b/types/react-dom/v15/react-dom-tests.ts index 865d74e386..5f5b149594 100644 --- a/types/react-dom/v15/react-dom-tests.ts +++ b/types/react-dom/v15/react-dom-tests.ts @@ -25,6 +25,8 @@ describe('ReactDOM', () => { const rootElement = document.createElement('div'); ReactDOM.render(React.createElement('div'), rootElement); ReactDOM.findDOMNode(rootElement); + ReactDOM.findDOMNode(null); + ReactDOM.findDOMNode(undefined); }); }); From 50cd191181c49bcf9948e5b76a22a11d810b72cb Mon Sep 17 00:00:00 2001 From: antoinebrault Date: Sat, 16 Feb 2019 10:40:10 -0500 Subject: [PATCH 03/11] [jest] fix test --- types/jest/jest-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index 11b3752a0a..b442e6825b 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -316,7 +316,7 @@ interface TestApi { test(x: number): string; } // $ExpectType Mock -const mock12 = jest.fn, ArgsType>(); +const mock12 = jest.fn, jest.ArgsType>(); // $ExpectType number mock1('test'); From 743fc6f72c1eff0159021588bf23c60c5ad8b480 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:30:24 +0500 Subject: [PATCH 04/11] Added co --- types/co/co-tests.ts | 21 +++++++++++++++++++++ types/co/index.d.ts | 17 +++++++++++++++++ types/co/tsconfig.json | 22 ++++++++++++++++++++++ types/co/tslint.json | 1 + 4 files changed, 61 insertions(+) create mode 100644 types/co/co-tests.ts create mode 100644 types/co/index.d.ts create mode 100644 types/co/tsconfig.json create mode 100644 types/co/tslint.json diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts new file mode 100644 index 0000000000..b610b280aa --- /dev/null +++ b/types/co/co-tests.ts @@ -0,0 +1,21 @@ +import co = require('co'); + +function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void){ + return num; +} + +co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.default(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); diff --git a/types/co/index.d.ts b/types/co/index.d.ts new file mode 100644 index 0000000000..0be8976a5f --- /dev/null +++ b/types/co/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for co 4.6 +// Project: https://github.com/tj/co#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type ExtractType = T extends IterableIterator ? R : never; + +interface Co { + Generator>(fn: F, ...args: Parameters): Promise>>; + default: Co; + co: Co; + wrap: Generator>(fn: F) => (...args: Parameters) => Promise>>; +} + +declare const co: Co; + +export = co; diff --git a/types/co/tsconfig.json b/types/co/tsconfig.json new file mode 100644 index 0000000000..dd6af28a07 --- /dev/null +++ b/types/co/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "co-tests.ts" + ] +} diff --git a/types/co/tslint.json b/types/co/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/co/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From fb4d0a9066e2dbd1730657f46173432ea1168f1c Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:37:09 +0500 Subject: [PATCH 05/11] Linter fixes --- types/co/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/co/tsconfig.json b/types/co/tsconfig.json index dd6af28a07..bc5a88eb32 100644 --- a/types/co/tsconfig.json +++ b/types/co/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 3316c2a06c9309219e710daa6f72e1476eee1681 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:41:45 +0500 Subject: [PATCH 06/11] Linter fixes --- types/co/co-tests.ts | 10 +++++----- types/co/index.d.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index b610b280aa..7348f77394 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -1,21 +1,21 @@ import co = require('co'); -function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void){ +function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void) { return num; } -co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) +co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); -co.default(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) +co.default(gen, 42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); -co.co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) +co.co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); -co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, function () {}) +co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); diff --git a/types/co/index.d.ts b/types/co/index.d.ts index 0be8976a5f..59fafd2495 100644 --- a/types/co/index.d.ts +++ b/types/co/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/tj/co#readme // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 type ExtractType = T extends IterableIterator ? R : never; From 932ca670c23e5c64675197f909e53833539bc930 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:44:01 +0500 Subject: [PATCH 07/11] Set author name --- types/co/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/co/index.d.ts b/types/co/index.d.ts index 59fafd2495..958c222a14 100644 --- a/types/co/index.d.ts +++ b/types/co/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for co 4.6 // Project: https://github.com/tj/co#readme -// Definitions by: My Self +// Definitions by: Doniyor Aliyev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 From 9104726fb6496af489492deda3d5f054c08a29ae Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 22:34:51 +0500 Subject: [PATCH 08/11] Added error tests --- types/co/co-tests.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index 7348f77394..b4459a1df2 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -19,3 +19,12 @@ co.co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}) co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); + +// $ExpectError +co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {}) + +// $ExpectError +co.wrap(gen)(); + +// $ExpectError +co.wrap(gen)('forty-two'); From 05bf4abb6d526f509dad16505a9bdf058a4867c4 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 22:37:37 +0500 Subject: [PATCH 09/11] Fixes --- types/co/co-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index b4459a1df2..159a2e90fb 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -21,7 +21,7 @@ co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {}) .catch((err: Error) => {}); // $ExpectError -co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {}) +co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {}); // $ExpectError co.wrap(gen)(); From 8209fca1342587edd536c44d99056f31a4bf61d3 Mon Sep 17 00:00:00 2001 From: Seth Kingsley Date: Sat, 16 Feb 2019 14:17:47 -0800 Subject: [PATCH 10/11] Remove myself from the contributor list Sorry, trying to cut down on notifications... --- types/three/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/three/index.d.ts b/types/three/index.d.ts index 420d48fe67..f929ef2383 100644 --- a/types/three/index.d.ts +++ b/types/three/index.d.ts @@ -17,7 +17,6 @@ // Daniel Hritzkiv , // Apurva Ojas , // Tiger Oakes , -// Seth Kingsley , // Ethan Kay , // Methuselah96 // Dilip Ramirez From 7be1cdad6de6b71ff107d70aa85beb727c959677 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Mon, 18 Feb 2019 11:54:11 +0100 Subject: [PATCH 11/11] fix(react-native): add missing properties to type Rationale Add missing types as documented here: https://facebook.github.io/react-native/docs/permissionsandroid --- types/react-native/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 99865ac3be..0cee14dfd2 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -7662,6 +7662,9 @@ export interface PanResponderStatic { export interface Rationale { title: string; message: string; + buttonPositive: string; + buttonNegative?: string; + buttonNeutral?: string; } export type Permission =