gpt4 book ai didi

javascript - 在 typescript 中隐式引用另一个内部模块

转载 作者:行者123 更新时间:2023-12-03 07:36:55 25 4
gpt4 key购买 nike

说我有

List.ts:

module Helper {
export class List{

}
}

Parser.ts:

module Helper {
export class Parser {
}
}

现在我有了另一个模块,每次我想使用“List”时,我都需要说Helper.List。是否可以直接说:

import Helper;

module Data {
export interface DataRepository {
getRange() : List<string>;
}
}

这样每次我想使用List时,我都可以只输入List而不是List.Helper?我知道你可以做到:

import List = Helper.List;

但是是这样的

import * from Helper; 

可能吗?

最佳答案

只有当您使用external modules时才有可能。 (推荐)。但是,您可以执行以下操作:

module Helper {
export class List<T> {

}
}

module Helper {
export class Parser {
}
}

module Data {
export interface DataRepository {
getRange() : Helper.List<string>;
}
}

或者

module Data {
type StringList = Helper.List<string>;
export interface DataRepository {
getRange() : StringList;
}
}

关于javascript - 在 typescript 中隐式引用另一个内部模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com