@darkobits/interop-import-default
Version:
TypeScript-friendly utility for extracting default exports from tricky packages.
18 lines (17 loc) • 716 B
TypeScript
export interface InteropImportDefaultOptions {
/**
* If true, `interopImportDefault` will require that the provided argument is
* an object. Any errors thrown (ex: by the Reflect API) will not be silently
* ignored.
*/
strict?: boolean;
}
/**
* Provided an object T, determines if that value has a property key 'default'.
* If so, returns its value as type T. Otherwise, returns the value as-is.
*
* If the provided value is not an object, it will returned as-is. If strict
* mode is enabled, the function will throw for non-objects and any other errors
* encountered.
*/
export declare function interopImportDefault<T>(packageExport: T, options?: InteropImportDefaultOptions): T;