Type error when running RxJS official `fromEvent` tutorial

793 Views Asked by At

I am trying to run the first example here. Rx.Observable.fromEvent(element, eventName, [selector])

But when compiling, the compiler throws me the following error.

Uncaught exception: { [TypeScript error: index.ts(44,38): Error TS2345: Argument of type 'JQuery' is not assignable to parameter of type 'Node'. Property 'attributes' is missing in type 'JQuery'.]
message: 'index.ts(44,38): Error TS2345: Argument of type \'JQuery\' is not assignable to parameter of type \'Node\'.\n Property \'attributes\' is missing in type \'JQuery\'.'

at

var source = Rx.Observable.fromEvent(input, 'click');

The input is

var input = $('#input');

The following is my imports:

/// <reference path="./typings/rx/rx.d.ts" />
/// <reference path="./typings/rx/rx.async.d.ts" />
/// <reference path="./typings/jquery/jquery.d.ts" />

import Rx = require('rx');
import $ = require('jquery');
1

There are 1 best solutions below

2
basarat On BEST ANSWER

Argument of type 'JQuery' is not assignable to parameter of type 'Node'

You need to access the underlying DOM element. One way is to use the string indexer [0] :

var source = Rx.Observable.fromEvent(input[0], 'click');