raveclassic / frp-ts

Functional reactive values-over-time
MIT License
79 stars 8 forks source link

`Property` example in README fails to compile #45

Closed mlrv closed 2 years ago

mlrv commented 2 years ago

One of the examples provided in the readme fails to compile. The following snippet is copy pasted directly from the readme.

import { newAtom, Property } from "@frp-ts/core"

interface Counter extends Property<number> {
  readonly inc: () => void
}

const newCounter = (initial: number): Counter => {
  const state = newAtom(initial)
  const inc = () => state.modify((n) => n + 1)

  return {
    subscribe: state.subscribe,
    get: state.get,
    inc,
  }
}

The snippet above fails to compile with the following error

Property '[Symbol.observable]' is missing in type '{ subscribe: (observer: Observer<number>) => Subscription; get: () => number; inc: () => void; }' but required in type 'Counter'.

Versions are as follows

"dependencies": {
    "@frp-ts/core": "^1.0.0-alpha.13",
    "@frp-ts/fp-ts": "^1.0.0-alpha.13",
    "@frp-ts/lens": "^1.0.0-alpha.13",
    "frp-ts": "^0.0.1"
  },
  "devDependencies": {
    "typescript": "^4.5.5"
  }
raveclassic commented 2 years ago

Hey @mlrv! Thanks for logging this issue. Yep, this is a regression caused by integration with Symbol.observable interop. We need to use newProperty instead of direct object construction via { }.