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 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
@now

This comment has been minimized.

Copy link

now 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

This comment has been minimized.

Copy link
Owner

zerobias commented Aug 8, 2019

Wow, I didn’t think it was possible 😄

@zerobias zerobias merged commit 7a42b23 into zerobias:master Aug 8, 2019
3 checks passed
3 checks passed
WIP Ready for review
Details
now Deployment has completed
Details
semaphoreci The build passed on Semaphore.
Details
@abliarsar abliarsar deleted the abliarsar:fix-filter-type branch Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.