-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update return type * add type tests (cherry picked from commit a1fb2cc) Co-authored-by: Qayyuum Harun <69181532+mqayyuum@users.noreply.github.com>
- Loading branch information
1 parent
be8cd0a
commit 2414bc9
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expectType, expectAssignable, expectNotAssignable } from 'tsd' | ||
import { Dispatcher, RetryHandler } from '../..' | ||
|
||
// Test the basic structure of RetryCallback | ||
expectType<RetryHandler.RetryCallback>((err, context, callback) => { | ||
expectType<Error>(err) | ||
expectType<{ | ||
state: RetryHandler.RetryState; | ||
opts: Dispatcher.DispatchOptions & { | ||
retryOptions?: RetryHandler.RetryOptions; | ||
}; | ||
}>(context) | ||
expectType<RetryHandler.OnRetryCallback>(callback) | ||
}) | ||
|
||
// Test that RetryCallback returns void | ||
const testCallback = (() => {}) as RetryHandler.RetryCallback | ||
const testContext = { | ||
state: {} as RetryHandler.RetryState, | ||
opts: {} as Dispatcher.DispatchOptions & { | ||
retryOptions?: RetryHandler.RetryOptions; | ||
} | ||
} | ||
|
||
expectType<void>(testCallback(new Error(), testContext, () => {})) | ||
|
||
// Test that the function is assignable to RetryCallback | ||
expectAssignable<RetryHandler.RetryCallback>(testCallback) | ||
|
||
// Test that an incorrectly typed function is not assignable to RetryCallback | ||
expectNotAssignable<RetryHandler.RetryCallback>((() => {}) as ( | ||
err: string, | ||
context: number, | ||
callback: boolean | ||
) => void) | ||
|
||
// Test the nested types | ||
const contextTest: Parameters<RetryHandler.RetryCallback>[1] = { | ||
state: {} as RetryHandler.RetryState, | ||
opts: { | ||
method: 'GET', | ||
path: 'some-path', | ||
retryOptions: {} as RetryHandler.RetryOptions | ||
} | ||
} | ||
expectType<RetryHandler.RetryState>(contextTest.state) | ||
expectType< | ||
Dispatcher.DispatchOptions & { retryOptions?: RetryHandler.RetryOptions } | ||
>(contextTest.opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters