diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts new file mode 100644 index 0000000000..159a2e90fb --- /dev/null +++ b/types/co/co-tests.ts @@ -0,0 +1,30 @@ +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 }, () => {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +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 }, () => {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +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'); diff --git a/types/co/index.d.ts b/types/co/index.d.ts new file mode 100644 index 0000000000..958c222a14 --- /dev/null +++ b/types/co/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for co 4.6 +// Project: https://github.com/tj/co#readme +// Definitions by: Doniyor Aliyev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 + +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..bc5a88eb32 --- /dev/null +++ b/types/co/tsconfig.json @@ -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", + "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" } diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 29b3210cc2..f0382d2cb5 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -978,20 +978,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[]; @@ -999,7 +1008,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 11b3752a0a..69e68ab6f7 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'); @@ -485,6 +485,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 = { 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); }); }); 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 = diff --git a/types/three/index.d.ts b/types/three/index.d.ts index 4e1f66e629..028ecc75dc 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