简体   繁体   English

加载 RxJS Typescript 类型而不从 CommonJS 模块导入?

[英]load RxJS Typescript typings without importing from CommonJS module?

I'm creating an Electron app with Typescript support.我正在创建一个支持 Typescript 的 Electron 应用程序。 I want to use RxJS library in the Renderer process with nodeIntegration set to false.我想在 Renderer 进程中使用 RxJS 库,并将 nodeIntegration 设置为 false。

In the specific window I include the RxJS by在特定窗口中,我包含了 RxJS

<script type="text/javascript" src="../node_modules/rxjs/bundles/rxjs.umd.min.js"></script>

In the Renderer Process I import specific observables and operators by在渲染器过程中,我通过以下方式导入特定的可观察对象和运算符

const { fromEvent } = (window as any).rxjs;//require('rxjs');
const { tap } = (window as any).rxjs.operators;//require("rxjs/operators");

Application works correctly but I have no support for types definitions from RxJS.应用程序工作正常,但我不支持来自 RxJS 的类型定义。 How can I bring the support back?我怎样才能恢复支持? How to import correctly the *.d.ts for RxJS?如何正确导入 RxJS 的 *.d.ts?

You can create your own .d.ts file like this:您可以像这样创建自己的 .d.ts 文件:

export * from 'rxjs'
export * as operators from 'rxjs/operators'
export * as testing from 'rxjs/testing'
export * as ajax from 'rxjs/ajax'
export * as webSocket from 'rxjs/webSocket'
export * as fetch from 'rxjs/fetch'

export as namespace rxjs

This way was suggested in this answer to a similar question.this answer to a similar question中建议了这种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将使用commonjs定义的类型转换为没有模块系统的类型 - Convert typings defined with commonjs into typings without a module system 在TypeScript(CommonJS)中导入模块而没有默认导出 - Importing modules without a default export in TypeScript (CommonJS) 如何在没有Typescript类型的情况下使用节点模块 - How to use an node module without typings from Typescript 用于打字稿的 Rxjs 打字 - Rxjs Typings for Typescript 在 TypeScript 中从 rrule 包导入 RRule。 获取 SyntaxError:请求的模块“rrule”应为 CommonJS 类型 - Importing RRule from rrule package in TypeScript. Getting SyntaxError: The requested module 'rrule' is expected to be of type CommonJS 在Typescript中使用CommonJS模块中的类 - Use class from CommonJS module in Typescript RxJS5 TypeScript 打字失败 - RxJS5 TypeScript typings fail 使用TypeScript中声明的模块的输入 - Use typings from a declared module in TypeScript 使用TypeScript使用Visual Studio中其他commonjs模块的类型(接口),而不必导入该模块? - Use types (interfaces) from other commonjs modules in Visual Studio using TypeScript without having to import that module? 从 TypeScript 导入 CommonJS 的最向前兼容的方式是什么? - What is the most forwards-compatible way of importing CommonJS from TypeScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM