From 2ed4b433bf3d091efe53888b017a762533c58c29 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 13 May 2024 11:28:49 +0200 Subject: [PATCH 1/3] fix: expose types and fix overloads for --- src/esm/api/register.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/esm/api/register.ts b/src/esm/api/register.ts index baafc37ff..861b18f3c 100644 --- a/src/esm/api/register.ts +++ b/src/esm/api/register.ts @@ -3,26 +3,28 @@ import { MessageChannel, type MessagePort } from 'node:worker_threads'; import type { Message } from '../types.js'; import { createScopedImport, type ScopedImport } from './scoped-import.js'; +export type { ScopedImport } from './scoped-import.js'; + export type InitializationOptions = { namespace?: string; 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 NamespacedRegister = { + import: ScopedImport; + unregister: Unregister; +} + +export type Unregister = () => Promise; + +export type Register = { + (options: RegisterOptions & Pick, 'namespace'>): Unregister & NamespacedRegister + (options?: RegisterOptions): Unregister; }; export const register: Register = ( From 4a5cdffcab70b3d8e826408cd2d431339416634c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 13 May 2024 11:40:28 +0200 Subject: [PATCH 2/3] chore: type exports --- src/esm/api/index.ts | 10 +++++++++- src/esm/api/register.ts | 10 +++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/esm/api/index.ts b/src/esm/api/index.ts index f976c3d4d..bce19ee05 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 ScopedImport, + type Unregister, +} from './register.js'; export { tsImport } from './ts-import.js'; diff --git a/src/esm/api/register.ts b/src/esm/api/register.ts index 861b18f3c..d55f3a264 100644 --- a/src/esm/api/register.ts +++ b/src/esm/api/register.ts @@ -15,15 +15,15 @@ export type RegisterOptions = { onImport?: (url: string) => void; }; -export type NamespacedRegister = { +export type Unregister = () => Promise; + +export type NamespacedUnregister = Unregister & { import: ScopedImport; unregister: Unregister; -} - -export type Unregister = () => Promise; +}; export type Register = { - (options: RegisterOptions & Pick, 'namespace'>): Unregister & NamespacedRegister + (options: RegisterOptions & Pick, 'namespace'>): NamespacedUnregister; (options?: RegisterOptions): Unregister; }; From 7eef7d985807372c426dc21547cbd6315f02ccee Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 13 May 2024 18:56:34 +0900 Subject: [PATCH 3/3] wip --- src/esm/api/index.ts | 2 +- src/esm/api/register.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/esm/api/index.ts b/src/esm/api/index.ts index bce19ee05..ff9bb4a0f 100644 --- a/src/esm/api/index.ts +++ b/src/esm/api/index.ts @@ -4,7 +4,7 @@ export { type NamespacedUnregister, type Register, type RegisterOptions, - type ScopedImport, 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 d55f3a264..6e610bea7 100644 --- a/src/esm/api/register.ts +++ b/src/esm/api/register.ts @@ -3,8 +3,6 @@ import { MessageChannel, type MessagePort } from 'node:worker_threads'; import type { Message } from '../types.js'; import { createScopedImport, type ScopedImport } from './scoped-import.js'; -export type { ScopedImport } from './scoped-import.js'; - export type InitializationOptions = { namespace?: string; port?: MessagePort; @@ -22,8 +20,10 @@ export type NamespacedUnregister = Unregister & { unregister: Unregister; }; +type RequiredProperty = Type & { [P in Keys]-?: Type[P] }; + export type Register = { - (options: RegisterOptions & Pick, 'namespace'>): NamespacedUnregister; + (options: RequiredProperty): NamespacedUnregister; (options?: RegisterOptions): Unregister; };