Skip to content

sample typings error #600

@meff34

Description

@meff34

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypingsTypescript public type definitions issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions