-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TypeScript - Fix return type when
immediate
option is set, correctl…
- Loading branch information
1 parent
314c5ef
commit 50319f6
Showing
2 changed files
with
33 additions
and
8 deletions.
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
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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
import {expectType} from 'tsd'; | ||
import {expectType, expectError} from 'tsd'; | ||
import debounceFn = require('.'); | ||
|
||
const options: debounceFn.Options = {}; | ||
const debounced = debounceFn((string: string) => true); | ||
expectType<((string: string) => boolean | undefined) & {cancel(): void}>(debounced); | ||
expectType<debounceFn.DebouncedFunction<[string], boolean | undefined>>( | ||
debounced | ||
); | ||
expectType<boolean | undefined>(debounced('foo')); | ||
debounced.cancel(); | ||
|
||
debounceFn((string: string) => true); | ||
debounceFn((string: string) => true, {wait: 100}); | ||
debounceFn((string: string) => true, {immediate: true}); | ||
const debouncedWithoutOptions = debounceFn((string: string) => true); | ||
expectType<boolean | undefined>(debouncedWithoutOptions('foo')); | ||
expectError<boolean>(debouncedWithoutOptions('foo')); | ||
|
||
const debouncedWithWait = debounceFn((string: string) => true, {wait: 100}); | ||
expectType<boolean | undefined>(debouncedWithWait('foo')); | ||
expectError<boolean>(debouncedWithWait('foo')); | ||
|
||
const debouncedWithImmediate = debounceFn((string: string) => true, { | ||
immediate: true | ||
}); | ||
expectType<boolean>(debouncedWithImmediate('foo')); |