Skip to content
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

Update type of Event.filter #170

Merged
merged 1 commit into from
Aug 8, 2019
Merged

Conversation

abliarsar
Copy link
Contributor

@abliarsar abliarsar commented Aug 8, 2019

Refine type of payload if filter got a predicate function as a callback

import { createEvent } from 'effector'

const event = createEvent<string | number>()

const isString = (value: any): value is string => typeof value === 'string'
const isNumber = (value: any): value is number => typeof value === 'number'

const str = event.filter({fn: isString}) // Event<string>
const num = event.filter({fn: isNumber}) // Event<number>

str.watch(value => value.slice()) // OK now
num.watch(value => value.toFixed(2)) // OK now

@vercel
Copy link

vercel bot commented Aug 8, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://effector-git-fork-abliarsar-fix-filter-type.zerobias.now.sh

@zerobias
Copy link
Member

zerobias commented Aug 8, 2019

Wow, I didn’t think it was possible 😄

@zerobias zerobias merged commit 7a42b23 into effector:master Aug 8, 2019
@abliarsar abliarsar deleted the fix-filter-type branch August 19, 2019 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants