[英]typescript import dependency with class
What is the best why to import this in typescript and get translate into js : 为何最好在typescript中导入它并转换成js:
const randomBytes = require('react-native-randombytes').randomBytes;
I do this: 我这样做:
import * as randomBytes from 'react-native-randombyte';
It only give me: 它只会给我:
const randomBytes = require('react-native-randombytes');
The syntax you're looking for is: 您要查找的语法是:
import { randomBytes } from 'react-native-randombyte';
This essentially means you want to import only randomBytes
, not the entire module. 这实质上意味着您只想导入
randomBytes
,而不是整个模块。 For more information, take a look at the TypeScript documentation here: 有关更多信息,请在此处查看TypeScript文档:
https://www.typescriptlang.org/docs/handbook/modules.html#import-a-single-export-from-a-module https://www.typescriptlang.org/docs/handbook/modules.html#import-a-single-export-from-a-module
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.