-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(equals): sufficently improve typings
- Loading branch information
1 parent
d9e5116
commit 24439ea
Showing
2 changed files
with
40 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { combine, Store } from 'effector'; | ||
import { combine, Store, Unit } from 'effector'; | ||
|
||
export function equals<A, B extends A>( | ||
a: A | Store<A>, | ||
b: B | Store<B>, | ||
export function equals<A, B>( | ||
a: A extends Unit<any> | ||
? A extends Store<infer First> | ||
? Store<First> | ||
: { error: `equals supports only stores and generic values` } | ||
: A, | ||
b: B extends Unit<any> | ||
? B extends Store<infer Second> | ||
? A extends Store<infer First> | ||
? Second extends First | ||
? Store<Second extends boolean ? boolean : Second> | ||
: { error: 'argument b should extends a' } | ||
: Second extends A | ||
? Second | ||
: { error: 'argument b should extends a' } | ||
: { error: `equals supports only stores and generic values` } | ||
: A extends Store<infer First> | ||
? B extends First | ||
? B | ||
: { error: 'argument b should extends a' } | ||
: B extends A | ||
? B | ||
: { error: 'argument b should extends a' }, | ||
): Store<boolean> { | ||
return combine(a as Store<A>, b as Store<B>, (a, b) => a === b); | ||
return combine(a as Store<A>, b as Store<A>, (a, b) => a === b); | ||
} |
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