typescript - 如何从同一个文件中导入两个同名的导出
问题描述
我有一个如下所示的 Typescript 文件:
export interface Prisma {
// Members
}
export const Prisma = (): Prisma => {
// returns a object with of type Prisma
};
鉴于这两个实体在同一个文件中具有相同的名称(我无法更改),我如何将接口导入另一个文件?写作
import Prisma from './myFile';
总是进口出口const
,从不出口interface
。
解决方案
基本上打字稿会Prisma
根据您使用它的位置来推断您,例如:
// Prisma.ts
export interface Prisma {
value: string;
}
export const Prisma = (): Prisma => {
return { value: "Some value" };
};
// File.ts
import { Prisma } from '.Prisma';
class MyClass implements Prisma {
value: string = "Initial value"; // => implement *interface*
// ...
getPrismaValue() {
return Prisma().value; // => execute Prisma *function*, yields "Some value"
}
}
推荐阅读
- javascript - 如何替换html文件中的正文
- apache-spark - spark - 应用程序根据不同的执行程序内存返回不同的结果?
- asp.net - 如何通过 HttpWebRequest - POST 使用 VB.net 传递 JSON 数据?
- c# - 从字符串日期 C# 获取 PM 或 AM
- typo3 - 带有引导警报的 TYPO3 felogin
- php - 按顺序执行命令的脚本php
- r - 从年初的年周数获取一周的第一天的日期
- dialogflow-es - Dialogflow 中具有排除值的实体
- xaml - 导航页面未在 XAML 中设置 BarBackgroundColor
- r - 如何在 R 中子集从 1.1.1961 到 31.12.2010 的时间段