简体   繁体   English

如何通过反应 typescript 获取 Electron 中的节点类型?

[英]How to get node types in Electron with react typescript?

Here is the code这是代码

in React App.tsx在 React App.tsx

const fs = window.require('fs')
fs.readFile(....)

Goal目标

  1. Get node module types获取节点模块类型
  2. Get node module intelliSense like fs.像 fs 一样获取节点模块智能感知。

Problem问题

If I want to use node module inside electron React project, I shoud require 'fs' from window, but this would loose node module types and intelliSense如果我想在 electron React 项目中使用节点模块,我应该要求 window 中的“fs”,但这会丢失节点模块类型和智能感知

You can use TypeScript import() types .您可以使用 TypeScript import() 类型

const fs: typeof import("fs") = window.require('fs');
fs.readFile(...)

在此处输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM