Skip to content

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