Skip to content

Commit 314f7a0

Browse files
leebyronsindresorhus
authored andcommitted
Fix Flow type ambiguity (#1164)
1 parent c84694b commit 314f7a0

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

index.js.flow

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,23 @@ type ContextualTestContext = TestContext & { context: any; };
9393
type ContextualCallbackTestContext = CallbackTestContext & { context: any; };
9494

9595
/**
96-
* Test Types
96+
* Test Implementations
9797
*/
9898

99-
type Test = (t: TestContext) => SpecialReturnTypes | void;
100-
type CallbackTest = (t: CallbackTestContext) => void;
101-
type ContextualTest = (t: ContextualTestContext) => SpecialReturnTypes | void;
102-
type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void;
103-
104-
/**
105-
* Macro Types
106-
*/
107-
108-
type Macro<T> = {
109-
(t: T, ...args: Array<any>): void;
99+
type TestFunction<T, R> = {
100+
(t: T, ...args: Array<any>): R;
110101
title?: (providedTitle: string, ...args: Array<any>) => string;
111102
};
112103

113-
type Macros<T> =
114-
| Macro<T>
115-
| Array<Macro<T>>;
104+
type TestImplementation<T, R> =
105+
| TestFunction<T, R>
106+
| Array<TestFunction<T, R>>;
107+
108+
type Test = TestImplementation<TestContext, SpecialReturnTypes | void>;
109+
type CallbackTest = TestImplementation<CallbackTestContext, void>;
110+
type ContextualTest = TestImplementation<ContextualTestContext, SpecialReturnTypes | void>;
111+
type ContextualCallbackTest = TestImplementation<ContextualCallbackTestContext, void>;
112+
116113

117114
/**
118115
* Method Types
@@ -121,8 +118,6 @@ type Macros<T> =
121118
type TestMethod = {
122119
( implementation: Test): void;
123120
(name: string, implementation: Test): void;
124-
( implementation: Macros<TestContext>, ...args: Array<any>): void;
125-
(name: string, implementation: Macros<TestContext>, ...args: Array<any>): void;
126121

127122
serial : TestMethod;
128123
before : TestMethod;
@@ -140,8 +135,6 @@ type TestMethod = {
140135
type CallbackTestMethod = {
141136
( implementation: CallbackTest): void;
142137
(name: string, implementation: CallbackTest): void;
143-
( implementation: Macros<CallbackTestContext>, ...args: Array<any>): void;
144-
(name: string, implementation: Macros<CallbackTestContext>, ...args: Array<any>): void;
145138

146139
serial : CallbackTestMethod;
147140
before : CallbackTestMethod;
@@ -159,8 +152,6 @@ type CallbackTestMethod = {
159152
type ContextualTestMethod = {
160153
( implementation: ContextualTest): void;
161154
(name: string, implementation: ContextualTest): void;
162-
( implementation: Macros<ContextualTestContext>, ...args: Array<any>): void;
163-
(name: string, implementation: Macros<ContextualTestContext>, ...args: Array<any>): void;
164155

165156
serial : ContextualTestMethod;
166157
before : ContextualTestMethod;
@@ -178,8 +169,6 @@ type ContextualTestMethod = {
178169
type ContextualCallbackTestMethod = {
179170
( implementation: ContextualCallbackTest): void;
180171
(name: string, implementation: ContextualCallbackTest): void;
181-
( implementation: Macros<ContextualCallbackTestContext>, ...args: Array<any>): void;
182-
(name: string, implementation: Macros<ContextualCallbackTestContext>, ...args: Array<any>): void;
183172

184173
serial : ContextualCallbackTestMethod;
185174
before : ContextualCallbackTestMethod;
@@ -201,8 +190,6 @@ type ContextualCallbackTestMethod = {
201190
declare module.exports: {
202191
( run: ContextualTest): void;
203192
(name: string, run: ContextualTest): void;
204-
( run: Macros<ContextualTestContext>, ...args: Array<any>): void;
205-
(name: string, run: Macros<ContextualTestContext>, ...args: Array<any>): void;
206193

207194
beforeEach : TestMethod;
208195
afterEach : TestMethod;

0 commit comments

Comments
 (0)