简体   繁体   English

如何在 React 中使用 Typed 包?

[英]How can I use Typed package in React?

I want to use the idm_db package with Typescript and React.我想将idm_db包与 Typescript 和 React 一起使用。 In its document, it only explains nodejs and also it does not support types.在它的文档中,它只解释了nodejs ,也不支持类型。 Luckily, there is @types/ibm_db and I think it supports types, but I cannot figure out how to use this one.幸运的是,有@types/ibm_db ,我认为它支持类型,但我不知道如何使用这个。

In nodejs,在 nodejs 中,

var ibmdb = require('ibm_db');

ibmdb.open("DATABASE=<dbname>;HOSTNAME=<myhost>;UID=db2user;PWD=password;PORT=<dbport>;PROTOCOL=TCPIP", function (err,conn) {
  if (err) return console.log(err);

  conn.query('select 1 from sysibm.sysdummy1', function (err, data) {
    if (err) console.log(err);
    else console.log(data);

    conn.close(function () {
      console.log('done');
    });
  });
});

node ibm_db节点 ibm_db

Following this one, I just changed first line, from var ibmdb = require('ibm_db');在此之后,我刚刚更改了第一行,从var ibmdb = require('ibm_db'); to import * asibmdb from 'ibm_db' . import * asibmdb from 'ibm_db' But, it keeps throwing an error related to webpack.(I don't use webpack at this point).但是,它不断抛出与 webpack 相关的错误。(此时我不使用 webpack)。 It compiles, but page is showing the error messages.它编译,但页面显示错误消息。

So, my question is, how can I use this package in React and Typescript way?所以,我的问题是,如何以 React 和 Typescript 的方式使用这个包? Thanks in advance!提前致谢!

EDIT It throws lots of errors and I am posting errors that I think it may cause.编辑它引发了很多错误,我发布了我认为可能导致的错误。

  28 |                      path.resolve(__dirname, '../installer/clidriver/lib');
  29 | }
  30 | 
> 31 | var odbc = require("bindings")("odbc_bindings")
  32 |   , SimpleQueue = require("./simple-queue")
  33 |   , util = require("util")
  34 |   , Readable = require('stream').Readable
199 |   // Avoids an infinite loop in rare cases, like the REPL
  200 |   dir = process.cwd();
  201 | }
> 202 | if (
      | ^  203 |   exists(join(dir, 'package.json')) ||
  204 |   exists(join(dir, 'node_modules'))
  205 | ) {
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {

For something like this, I might use对于这样的事情,我可能会使用

import * as ibmdb from 'ibm_db';

Does that help?这有帮助吗? Some reference: https://stackoverflow.com/a/43172907/8678978一些参考: https : //stackoverflow.com/a/43172907/8678978

I have the same issue when I use the moment package in React with typescript当我在 React 中使用带有打字稿的moment包时遇到了同样的问题

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

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