cycle/dom stream library specific typings
See original GitHub issueAs 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:
- Created 7 years ago
- Comments:20 (14 by maintainers)
Top GitHub Comments
We can’t seem to find how to automagically make
DOMSource
know which stream library type it is returning viaevents()
. 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()
andelements
: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.I believe this issue is now solved with
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 makingrxjs-typings
etc should be straight-forward, we will do that next.