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

sample typings error #600

Closed
meff34 opened this issue Jan 13, 2022 · 1 comment
Closed

sample typings error #600

meff34 opened this issue Jan 13, 2022 · 1 comment
Labels
bug Something isn't working typings Typescript public type definitions issues

Comments

@meff34
Copy link

meff34 commented Jan 13, 2022

What is the current behavior:
The sample operator allows sampling from unknown to narrower types.

Steps to reproduce:
www.typescriptlang.org/play

import { createEvent, forward, sample } from 'effector'

const emitUnknown = createEvent<unknown>()
const receiveNumber = createEvent<number>()

sample({
  // @ts-expect-error: unused directive ❌
  source: emitUnknown,
  target: receiveNumber,
})

forward({
  // @ts-expect-error: type 'unknown' is not assignable to type 'number'. ✅
  from: emitUnknown, 
  to: receiveNumber,
})

What is the expected behavior:
The "sample" is expected to work identically to the "forward" in this case: throw compilation error "type 'unknown' is not assignable to type 'number'"

Versions:
Reproduces on effector@22.1.2 and typescript@4.5.4

@meff34 meff34 added bug Something isn't working needs triage labels Jan 13, 2022
@egorguscha egorguscha added the typings Typescript public type definitions issues label Jan 13, 2022
@zerobias zerobias added this to the effector 22.2.0 milestone Jan 13, 2022
zerobias added a commit that referenced this issue Jan 13, 2022
new tests show that issue with sample is already fixed

related issue #600
@zerobias
Copy link
Member

Already fixed in master, I added a test for your case and it has pretty clear error message:
image

The fix will be published in next minor release

zerobias added a commit that referenced this issue Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typings Typescript public type definitions issues
Projects
None yet
Development

No branches or pull requests

3 participants