|
3 | 3 | /// <reference path="./cypress-eventemitter.d.ts" />
|
4 | 4 | /// <reference path="./cypress-type-helpers.d.ts" />
|
5 | 5 |
|
| 6 | +type IsAny<X> = |
| 7 | + (<T>() => T extends X ? 1 : 2) extends |
| 8 | + (<T>() => T extends any ? 1 : 2) ? true : false; |
| 9 | + |
| 10 | +type CypressConfig_Data = typeof import('../../../cypress.config') |
| 11 | +type AllTasks_CJS = CypressConfig_Data['CypressTasks'] |
| 12 | +type AllTasks_ESM = CypressConfig_Data['default']['CypressTasks'] |
| 13 | + |
| 14 | +type AllTasks = IsAny<AllTasks_CJS> extends true ? AllTasks_ESM : AllTasks_CJS |
| 15 | +type TaskEventNames = keyof AllTasks & string |
| 16 | + |
| 17 | +type MyParameter<T extends TaskEventNames> = Parameters<AllTasks[T]>[0] |
| 18 | +type MyReturnType<T extends TaskEventNames> = Awaited<ReturnType<AllTasks[T]>> |
| 19 | + |
6 | 20 | declare namespace Cypress {
|
7 | 21 | type FileContents = string | any[] | object
|
8 | 22 | type HistoryDirection = 'back' | 'forward'
|
@@ -2164,7 +2178,23 @@ declare namespace Cypress {
|
2164 | 2178 | *
|
2165 | 2179 | * @see https://on.cypress.io/api/task
|
2166 | 2180 | */
|
2167 |
| - task<S = unknown>(event: string, arg?: any, options?: Partial<Loggable & Timeoutable>): Chainable<S> |
| 2181 | + task<T extends TaskEventNames>( |
| 2182 | + event: T, |
| 2183 | + ...myArgs: IsAny<AllTasks> extends true ? |
| 2184 | + [ |
| 2185 | + arg?: any, |
| 2186 | + options?: Partial<Loggable & Timeoutable> |
| 2187 | + ] : Parameters<AllTasks[T]>['length'] extends 0 ? |
| 2188 | + [ |
| 2189 | + arg?: undefined, |
| 2190 | + options?: Partial<Loggable & Timeoutable> |
| 2191 | + ] : [ |
| 2192 | + arg: MyParameter<T>, |
| 2193 | + options?: Partial<Loggable & Timeoutable> |
| 2194 | + ] |
| 2195 | + ): Chainable< |
| 2196 | + IsAny<AllTasks> extends true ? unknown : MyReturnType<T> |
| 2197 | + > |
2168 | 2198 |
|
2169 | 2199 | /**
|
2170 | 2200 | * Enables you to work with the subject yielded from the previous command.
|
|
0 commit comments