From 2c87fc156b6343b1ac789ecd5de0a4b64a2f7361 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 13 May 2024 11:57:18 +0200 Subject: [PATCH] fix: expose types for `esm/api` (#551) Co-authored-by: Hiroki Osame --- src/esm/api/index.ts | 10 +++++++++- src/esm/api/register.ts | 24 +++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/esm/api/index.ts b/src/esm/api/index.ts index f976c3d4d..ff9bb4a0f 100644 --- a/src/esm/api/index.ts +++ b/src/esm/api/index.ts @@ -1,2 +1,10 @@ -export { register } from './register.js'; +export { + register, + type InitializationOptions, + type NamespacedUnregister, + type Register, + type RegisterOptions, + type Unregister, +} from './register.js'; +export type { ScopedImport } from './scoped-import.js'; export { tsImport } from './ts-import.js'; diff --git a/src/esm/api/register.ts b/src/esm/api/register.ts index baafc37ff..6e610bea7 100644 --- a/src/esm/api/register.ts +++ b/src/esm/api/register.ts @@ -8,21 +8,23 @@ export type InitializationOptions = { port?: MessagePort; }; -type Options = { +export type RegisterOptions = { namespace?: string; onImport?: (url: string) => void; }; -type Unregister = () => Promise; -type Register = { - (options: { - namespace: string; - onImport?: (url: string) => void; - }): Unregister & { - import: ScopedImport; - unregister: Unregister; - }; - (options?: Options): Unregister; +export type Unregister = () => Promise; + +export type NamespacedUnregister = Unregister & { + import: ScopedImport; + unregister: Unregister; +}; + +type RequiredProperty = Type & { [P in Keys]-?: Type[P] }; + +export type Register = { + (options: RequiredProperty): NamespacedUnregister; + (options?: RegisterOptions): Unregister; }; export const register: Register = (