【问题标题】:Import specific types with alias in typescript在打字稿中使用别名导入特定类型
【发布时间】:2019-11-02 10:17:39
【问题描述】:

我可以将特定类型导入为

import { Type1, Type2 } from '../../my-file';

我可以从别名为的文件中导入所有类型

import * as fromApp from '../../../store/app.reducers';

如何使用别名导入特定类型,例如

import { Type1, Type2 } as MyTypes from '../../my-file'; // of-course, this does not work

【问题讨论】:

  • 那么你认为类型的最终用途是什么?如果您正在寻找MyTypes.Type1MyTypes.Type2,您可以使用import * as MyTypes 语句。
  • 但是如果有一个不需要的Type3,最好只为Type1Type2定义一个别名。
  • 你知道需要更少的类型并不会改变构建过程的任何内容,只需使用* as Whatever,如果你只是在谈论类型

标签: angular typescript import


【解决方案1】:

你能做的最接近的事情:

import {Type1, Type2} from '../../my-file';

const MyTypes = {Type1, Type2};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多