简体   繁体   English

如何将TypeScript导入语句转换为JS Require语句

[英]How to convert a TypeScript import statement into a JS Require statement

How would I convert the follow TS statement 我将如何转换Follow TS语句

import {TNSFontIcon, fonticon} from 'nativescript-fonticon';

Into a Javascript require statement? 变成Java语言的require语句? My thought is: 我的想法是:

TNSFontIcon = require('nativescript-fonticon’).TNSFontIcon()

But the TS statement is importing multiple things from the file... 但是TS语句正在从文件中导入多个内容...

Ideally you can write: 理想情况下,您可以编写:

var package = require('nativescript-fonticon');

var TNSFontIcon = package.TNSFontIcon;
var fonticon = package.fonticon;

// and later use it as follows
var obj = new TNSFontIcon();

This assumes that nativescript-fonticon is a commonjs package. 假设nativescript-fonticoncommonjs包。 If you're compiling the nativescript-fonticon from TypeScript you can choose from various output formats, see: https://www.typescriptlang.org/docs/handbook/compiler-options.html 如果要从TypeScript编译nativescript-fonticon ,则可以从各种输出格式中进行选择,请参阅: https : nativescript-fonticon

Note that require isn't a standard JavaScript function and you need to polyfill with eg. 请注意, require不是标准的JavaScript函数,您需要使用eg进行填充。 requirejs . requirejs

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

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