1.1.3 • Published 1 month ago

@homer0/ts-async-import v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

☢️ TS Async Import

A wrapper to do dynamic imports in TypeScript contexts that target CommonJS.

🍿 Usage

⚠️ Don't use this package if you are targeting ES modules.

⚙️ Examples

import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } =
  await tsAsyncImport<typeof import('node-fetch')>('node-fetch');

That's it, the only difference between this and a regular import is that you need to specify the type of the module you are importing.

And, if for some reason, you want to specify the context path for the import, you can do it with the second parameter:

import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } = await tsAsyncImport<typeof import('node-fetch')>(
  'node-fetch',
  __dirname,
);

🤘 Development

As this project is part of the packages monorepo, some of the tooling, like lint-staged and husky, are installed on the root's package.json.

Tasks

TaskDescription
lintLints the package.
testRuns the unit tests.
types:checkValidates the TypeScript types.

Motivation

I didn't want to have to change my tsconfig.json just to prevent TS to transform the two imports I have into requires 🤬.

1.1.3

1 month ago

1.1.2

2 months ago

1.1.1

3 months ago

1.1.0

5 months ago