Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TypeScript types #301

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ESMSInitOptions {
/**
* Disable retriggering of document readystate
*/
noLoadEventRetriggers: true,
noLoadEventRetriggers: true;

/**
* #### Skip Processing Stability
Expand All @@ -45,24 +45,28 @@ interface ESMSInitOptions {

/**
* #### Error hook
*
*
* Register a callback for any ES Module Shims module errors.
*
*
*/
onerror: (e: any) => any;

/**
* #### Resolve Hook
*
*
* Only supported in Shim Mode.
*
*
* Provide a custom resolver function.
*/
resolve: (id: string, parentUrl: string, resolve: (id: string, parentUrl: string) => string) => string | Promise<string>;
resolve: (
id: string,
parentUrl: string,
resolve: (id: string, parentUrl: string) => string
) => string | Promise<string>;
Comment on lines +61 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier did this but I figured I'd leave it in since it's less likely to cause more diffs in the future (assuming most devs have Prettier running).


/**
* #### Fetch Hook
*
*
* Only supported in Shim Mode.
*
* > Stability: Non-spec feature
Expand Down Expand Up @@ -126,14 +130,19 @@ interface ESMSInitOptions {

/**
* #### Revoke Blob URLs
*
*
* Set to *true* to cleanup blob URLs from memory after execution.
* Can cost some compute time for large loads.
*
*
*/
revokeBlobURLs: boolean;
}

interface ImportMap {
imports: Record<string, string>;
scopes: Record<string, Record<string, string>>;
}

/**
* Dynamic import(...) within any modules loaded will be rewritten as
* importShim(...) automatically providing full support for all es-module-shims
Expand All @@ -151,6 +160,12 @@ declare function importShim<Default, Exports extends object>(
parentUrl?: string
): Promise<{ default: Default } & Exports>;

declare namespace importShim {
const resolve: (id: string, parentURL?: string) => string;
const addImportMap: (importMap: Partial<ImportMap>) => void;
const getImportMap: () => ImportMap;
}

interface Window {
esmsInitOptions?: ESMSInitOptions;
importShim: typeof importShim;
Expand Down