Skip to content

Commit 2c87fc1

Browse files
antfuprivatenumber
andauthoredMay 13, 2024··
fix: expose types for esm/api (#551)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
1 parent 069c39f commit 2c87fc1

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
 

‎src/esm/api/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
export { register } from './register.js';
1+
export {
2+
register,
3+
type InitializationOptions,
4+
type NamespacedUnregister,
5+
type Register,
6+
type RegisterOptions,
7+
type Unregister,
8+
} from './register.js';
9+
export type { ScopedImport } from './scoped-import.js';
210
export { tsImport } from './ts-import.js';

‎src/esm/api/register.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ export type InitializationOptions = {
88
port?: MessagePort;
99
};
1010

11-
type Options = {
11+
export type RegisterOptions = {
1212
namespace?: string;
1313
onImport?: (url: string) => void;
1414
};
1515

16-
type Unregister = () => Promise<void>;
17-
type Register = {
18-
(options: {
19-
namespace: string;
20-
onImport?: (url: string) => void;
21-
}): Unregister & {
22-
import: ScopedImport;
23-
unregister: Unregister;
24-
};
25-
(options?: Options): Unregister;
16+
export type Unregister = () => Promise<void>;
17+
18+
export type NamespacedUnregister = Unregister & {
19+
import: ScopedImport;
20+
unregister: Unregister;
21+
};
22+
23+
type RequiredProperty<Type, Keys extends keyof Type> = Type & { [P in Keys]-?: Type[P] };
24+
25+
export type Register = {
26+
(options: RequiredProperty<RegisterOptions, 'namespace'>): NamespacedUnregister;
27+
(options?: RegisterOptions): Unregister;
2628
};
2729

2830
export const register: Register = (

0 commit comments

Comments
 (0)
Please sign in to comment.