diff --git a/packages/kerosene-ui/package.json b/packages/kerosene-ui/package.json index b39bfac..203abe5 100644 --- a/packages/kerosene-ui/package.json +++ b/packages/kerosene-ui/package.json @@ -1,6 +1,6 @@ { "name": "@kablamo/kerosene-ui", - "version": "0.0.16", + "version": "0.0.17", "repository": "https://github.com/KablamoOSS/kerosene/tree/master/packages/kerosene-ui", "bugs": { "url": "https://github.com/KablamoOSS/kerosene/issues" diff --git a/packages/kerosene-ui/src/types/index.ts b/packages/kerosene-ui/src/types/index.ts index 47ff0e4..f55d7d3 100644 --- a/packages/kerosene-ui/src/types/index.ts +++ b/packages/kerosene-ui/src/types/index.ts @@ -1,34 +1,21 @@ /** - * Used internally by `UnwrapComponent` to unwrap a single layer decorator-wrapped component - * @private + * Unwraps the decorated typings from a decorator-wrapped components to provide the original type of the underlying + * component. Useful in unit testing when stubbing decorators with the identity function. */ -export type _UnwrapComponent = T extends React.MemoExoticComponent< +export type UnwrapComponent = T extends React.MemoExoticComponent< infer TMemoComponent > - ? TMemoComponent + ? { 0: UnwrapComponent }[TMemoComponent extends any + ? 0 + : never] : T extends React.LazyExoticComponent - ? TLazyComponent + ? { 0: UnwrapComponent }[TLazyComponent extends any + ? 0 + : never] : "WrappedComponent" extends keyof T - // @ts-ignore - ? T["WrappedComponent"] + ? { + // @ts-ignore + 0: UnwrapComponent; + // @ts-ignore + }[T["WrappedComponent"] extends any ? 0 : never] : T; - -/** - * Unwraps the decorated typings from a decorator-wrapped components to provide the original type of the underlying - * component. Useful in unit testing when stubbing decorators with the identity function. - * - * Note: This will unwrap up to 8 layers of decorators as although TypeScript supports recursive types, it does not - * allow recursive type arguments. If more levels are required, you may use the `_UnwrapComponent` type to unwrap - * a single layer at a time. - */ -export type UnwrapComponent = _UnwrapComponent< - _UnwrapComponent< - _UnwrapComponent< - _UnwrapComponent< - _UnwrapComponent< - _UnwrapComponent<_UnwrapComponent<_UnwrapComponent>> - > - > - > - > ->;