question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cycle/dom stream library specific typings

See original GitHub issue

As discussed in point (4) of #307 regarding Typescript typings, @cycle/dom’s (RC) DOMSource.events() returns any. This is done intentionally, as cycle’s future is to be stream library agnostic, i.e. it should be able to be used with xstream, RxJS, most, etc.

However from an application developer’s point of view, DOMSource.events() would ideally return the type appropriate to the stream library (in xstream’s case Stream<Event>), as this will help with compile time and edit time error checking and intellisense.

This issue is not specific to @cycle/dom. Any cyclejs driver which is stream library agnostic would have a similar problem. Solving this issue for @cycle/dom would set a common approach for all cyclejs drivers.

On approach would be to create a set of typings specific to each stream library. For example, for @cycle/dom, I have a simplified set of typings in my application’s custom-typings directory:

import { IDOMSource, EventsFnOptions } from '@cycle/dom';
import { Stream } from 'xstream';

declare module '@cycle/dom' {
    export class DOMSource {
        select(selector: string): DOMSource;
        events(eventType: string, options?: EventsFnOptions): Stream<Event>;
    }
}

This issue is to discuss the best and most convenient options for solving this typings issue for cyclejs drivers.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

6reactions
staltzcommented, Jun 7, 2016

We can’t seem to find how to automagically make DOMSource know which stream library type it is returning via events(). That would be the ideal case, but we are hitting the limits of TypeScript. So which of these two options seems the least worst?

(1) DOMSource is a generic and you need to tell what are the types it returns when calling events() and elements: DOMSource<Stream<Event>, Stream<Element>>. This would need to be typed anywhere we have a function that expects a DOMSource. React with 👍 if you want this option.

(2) A custom typings file similar to what you made, but it would have to be imported separately and included via typings for instance. After that, everything works automagically. React with ❤️ if you want this option.

3reactions
staltzcommented, Jun 8, 2016

I believe this issue is now solved with

    "@cycle/dom": "10.0.0-rc30",
    "@cycle/http": "9.0.0-rc8",

and solution (3).

Check out these examples: https://github.com/cyclejs/examples/tree/diversity/http-random-user https://github.com/cyclejs/examples/tree/diversity/bmi-typescript

So far, only @cycle/...../xstream-typings is available, but making rxjs-typings etc should be straight-forward, we will do that next.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript typings in Cyclejs for Mostjs stream interoperability?
For most.js with Cycle DOM, you need to grab the typings separately: import {DOMSource} from '@cycle/dom/most-typings.d.ts'.
Read more >
Releases - Cycle - JS.ORG
As an additional feature, Cycle DOM recognizes special scope strings: ':root' ... Each stream library had its corresponding adapter package, ...
Read more >
Press Play: Recorded Sound from Groove to Stream
We've created a playlist of 53 recordings accompanying Press Play you may access via the listening station in Special Collections, by clicking ...
Read more >
Download & Stream | Indianapolis Public Library
Download & stream free books, movies, music, comics and magazines anytime, anywhere on any device by using your library card.
Read more >
Carol Stream Public Library: Home
Due to forecasts for severe weather, the Library is closing Thursday, December 22 at 5 pm; we will remain closed all day on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found