我们什么时候使用 typescript import * as? [英] When do we use typescript import * as?

查看:33
本文介绍了我们什么时候使用 typescript import * as?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为 import * as Blah 所做的事情开发一个心智模型.例如:

Trying to developer a mental model for what import * as Blah does. For example:

import * as StackTrace from 'stacktrace-js';

它是如何工作的,我们什么时候做import *?

How does that work and when do we do import *?

推荐答案

不是真正的答案,而是一种用法:考虑到您的应用程序中要使用一些常量字符串,您可以在单个文件中定义它们并导出

Not really an answer, but a usage: Consider you have a few constant strings to be used in your application, you can define them in a single file and export

export const name = "NAME";
export const someOtherString = "SOME_CONST_STRING";

然后您可以使用以下方法将它们导入到单个变量中:

Then you can import them in a single variable using:

import * as CONST_STRINGS from './yourFilePath';

并用作

CONST_STRINGS.name 
CONST_STRINGS.someOtherString

这篇关于我们什么时候使用 typescript import * as?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆