New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generic typeguard do not work as filter #811
Comments
I have one more case when typescript does not report an error with the import {sample, createEvent, createStore} from "effector";
type AnyObject = {
name: string;
}
function isDefined<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}
const voidEvent = createEvent();
const stringEvent = createEvent<string>();
const $nullableStore = createStore<AnyObject | null>(null);
sample({
clock: voidEvent,
source: $nullableStore,
filter: isDefined,
target: stringEvent
}); |
Function which uses type guard is not a type guard, so filter will not work in typescript at all, this is not related to effector |
zerobias
added
invalid
This doesn't seem right
and removed
bug
Something isn't working
needs triage
labels
Apr 15, 2023
@zerobias But sample({
clock: whenFeedCat,
source: $activePet,
filter: isCat,
fn: (cat, time) => ({milk: cat.milkSounds, time}), // TS error
target: printMilkFx
})
// ***
function isCat<A>(pet: Pet<any, A>): pet is Catty<A> {
return pet._tag === 'Cat';
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the current behavior:
https://tsplay.dev/wXq5JN
What is the expected behavior:
Proper types
Which versions of effector packages, and which browser and OS are affected by this issue? Did this work in previous versions of effector?:
latest
The text was updated successfully, but these errors were encountered: