Skip to content

Commit

Permalink
fix: expose types for esm/api (#551)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
  • Loading branch information
antfu and privatenumber committed May 13, 2024
1 parent 069c39f commit 2c87fc1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/esm/api/index.ts
Original file line number Diff line number Diff line change
@@ -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';
24 changes: 13 additions & 11 deletions src/esm/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ export type InitializationOptions = {
port?: MessagePort;
};

type Options = {
export type RegisterOptions = {
namespace?: string;
onImport?: (url: string) => void;
};

type Unregister = () => Promise<void>;
type Register = {
(options: {
namespace: string;
onImport?: (url: string) => void;
}): Unregister & {
import: ScopedImport;
unregister: Unregister;
};
(options?: Options): Unregister;
export type Unregister = () => Promise<void>;

export type NamespacedUnregister = Unregister & {
import: ScopedImport;
unregister: Unregister;
};

type RequiredProperty<Type, Keys extends keyof Type> = Type & { [P in Keys]-?: Type[P] };

export type Register = {
(options: RequiredProperty<RegisterOptions, 'namespace'>): NamespacedUnregister;
(options?: RegisterOptions): Unregister;
};

export const register: Register = (
Expand Down

0 comments on commit 2c87fc1

Please sign in to comment.