Skip to content

Typescript typings for sample  #155

@abliarsar

Description

@abliarsar

Sample typings is incomplete for config case.

const source = createStore<string>('')
const event = createEvent<number>()

const target = createEvent<number>()

// Fine
const case1 = sample(source, event, (a, b) => 1)

const store = createStore<number>()
const event2 = createEvent<string>()
// Should be Event<number>, not Event<string>
const case1bug = sample(event2, store, (a,b) => 1)

// No errors, but case2 should be Event, not Unit
// It doesn't matter tho, because we can use methods of target
const case2 = sample({
  source,
  clock: event,
  fn: (a, b) => 1,
  target
})
// TS complains about arguments of fn
// TS7006: Parameter 'a' implicitly has an 'any' type.
// TS7006: Parameter 'b' implicitly has an 'any' type.
const case3 = sample({
  source,
  clock: event,
  fn: (a, b) => 1
})

// And case3 is completely useless, because it has Unit type
// TS2339: Property 'filterMap' does not exist on type 'Unit<number>'.
case3.filterMap(a => a === 1 ? a : undefined)
// Can't cast it
// TS2740: Type 'Unit<number>' is missing the following properties from type 'Event<number>': watch, map, filter, filterMap, and 5 more.
const t: Event<number> = case3

Metadata

Metadata

Assignees

No one assigned

    Labels

    typingsTypescript public type definitions issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions