I have a Typescript file that looks like this:
export interface Prisma {
// Members
}
export const Prisma = (): Prisma => {
// returns a object with of type Prisma
};
Run Code Online (Sandbox Code Playgroud)
Given that both of these entities have the same name in the same file (which I can't change), how can I import the interface in another file? Writing
import Prisma from './myFile';
Run Code Online (Sandbox Code Playgroud)
always imports the exported const, never the exported 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"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
577 次 |
| 最近记录: |