How to import two exports with the same name from the same file

Viewed 1693

I have a Typescript file that looks like this:

export interface Prisma {
    // Members
}

export const Prisma = (): Prisma => {
    // returns a object with of type Prisma
};

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';

always imports the exported const, never the exported interface.

1 Answers

Basically typescript will infer your Prisma based on where you use it, for example:

// 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"
  }
}
Related