How do I import a type definition from a module in JavaScript+JSDoc?

28 Views Asked by At

I am trying to import a type definition from a module in JSDoc into my SvelteKit application.

This is the TypeScript code I'm trying to implement as JS/JSDoc:

import type { PostgreSqlDriver } from '@mikro-orm/postgresql'; // or any other driver package

const orm = await MikroORM.init<PostgreSqlDriver>({
  entities: ['./dist/entities'], // path to our JS entities (dist), relative to `baseDir`
  entitiesTs: ['./src/entities'], // path to our TS entities (src), relative to `baseDir`
  dbName: 'my-db-name',
  type: 'postgresql',
});
console.log(orm.em); // access EntityManager via `em` property

(Taken from https://mikro-orm.io/docs/5.9/installation)

Here's what I have so far, VS Code errors as inline comments

import { MikroORM } from '@mikro-orm/core';

/** @type {import("@mikro-orm/postgresql").PostgreSqlDriver } */

/** @type {PostgreSqlDriver } */ // Cannot find name 'PostgreSqlDriver'.ts(2304)
export const orm = await MikroORM.init({
    dbName: 'my-db-name',
    type: 'postgresql',
});
1

There are 1 best solutions below

0
Martin Adámek On

I can't help you with jsdoc, that's not my cup of tea, but you are dealing with something that has much simpler solution - just import the ORM from the driver package:

import { MikroORM } from '@mikro-orm/postgresql';

export const orm = await MikroORM.init({
    dbName: 'my-db-name',
});