43259

RxJS5 TypeScript typings fail

Question:

I run tsc on my project, and I get these errors relating to the RxJS5 lib:

$ tsc node_modules/rxjs/observable/FromEventObservable.d.ts(11,39): error TS2304: Cannot find name 'EventTarget'. node_modules/rxjs/observable/FromEventObservable.d.ts(11,103): error TS2304: Cannot find name 'NodeList'. node_modules/rxjs/observable/FromEventObservable.d.ts(11,114): error TS2304: Cannot find name 'HTMLCollection'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(16,23): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(77,59): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(82,13): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(97,20): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(98,10): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(108,32): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(108,44): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(119,10): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(128,39): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/AjaxObservable.d.ts(136,22): error TS2304: Cannot find name 'XMLHttpRequest'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(10,29): error TS2304: Cannot find name 'MessageEvent'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(11,33): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(12,34): error TS2304: Cannot find name 'CloseEvent'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(15,63): error TS2304: Cannot find name 'WebSocket'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(27,13): error TS2304: Cannot find name 'WebSocket'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(28,32): error TS2304: Cannot find name 'Event'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(29,33): error TS2304: Cannot find name 'CloseEvent'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(32,63): error TS2304: Cannot find name 'WebSocket'. node_modules/rxjs/observable/dom/WebSocketSubject.d.ts(36,23): error TS2304: Cannot find name 'MessageEvent'.

does anyone know why this is happening? this is my package.json file:

{ "name": "oplog.rx", "version": "0.0.101", "description": "", "main": "index.js", "scripts": { "test": "suman test" }, "repository": { "type": "git", "url": "git+https://github.com/ORESoftware/oplog.rx.git" }, "keywords": [ "oplog", "mongodb", "rx", "rxjs" ], "author": "Olegzandr V.D.", "license": "MIT", "bugs": { "url": "https://github.com/ORESoftware/oplog.rx/issues" }, "homepage": "https://github.com/ORESoftware/oplog.rx#readme", "dependencies": { "bson": "^2.0.4", "json-stdio": "0.0.1016", "mongodb": "^3.0.4", "rxjs": "^5.5.7" }, "devDependencies": { "@types/mongodb": "^3.0.8" } }

Answer1:

You need to add "dom" to the lib setting in your tsconfig.json file's compilerOptions:

"lib": ["dom", "es2015"]

Alternatively, you can use the skipLibCheck compilerOption to avoid checking .d.ts files within node_modules:

"skipLibCheck": true

See <a href="https://github.com/ReactiveX/rxjs/issues/3558" rel="nofollow">this issue</a> for an explanation.

Basically, the fromEvent observable factory supports both Node and DOM event sources and TypeScript needs to know about the DOM types.

<a href="https://github.com/ReactiveX/rxjs/pull/3566" rel="nofollow">This PR</a> should resolve the problem.

Recommend

  • Waiting slots to be executed before quitting
  • cost of observing large collection with oplog tailing
  • Selective replication in mongodb
  • Android Wear Message Listener
  • How to control QProgressBar with Signal
  • Query on MongoDB Delete Triggers
  • RxJS5 TypeScript typings fail
  • When does OnWebSocketClose fire in Jetty 9
  • Generating a QCloseEvent won't close QMainWindow
  • Having problems with global variable in python and line api [duplicate]
  • MongoDB replication crashes and wouldn't start up again
  • WPF WebBrowser - detecting redirects?
  • getting remote ip address in connectionless server
  • http request every x seconds in angular
  • non-conformable arrays when passing numpy array to R via rpy2
  • RS-232 communication using an Arduino Duemilanove and the Cutedigi RS-232 interface
  • Angular5 Service Worker update(SWUpdate) not detecting on firefox. Working on chrome
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Read text file that is not in the main package in a runnable jar
  • Roxygen error “Skipping invalid path”
  • Play WS (2.2.1): post/put large request
  • Different response to non-authenticated users and AJAX calls
  • Deserializing XML into class C#
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How to include full .NET prerequisite for Wix Burn installer
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Is it possible to post an object from jquery to bottle.py?
  • costura.fody for a dll that references another dll
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize