Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/kerosene-ui/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
41 changes: 14 additions & 27 deletions packages/kerosene-ui/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
/**
* Used internally by `UnwrapComponent<T>` 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> = T extends React.MemoExoticComponent<
export type UnwrapComponent<T> = T extends React.MemoExoticComponent<
infer TMemoComponent
>
? TMemoComponent
? { 0: UnwrapComponent<TMemoComponent> }[TMemoComponent extends any
? 0
: never]
: T extends React.LazyExoticComponent<infer TLazyComponent>
? TLazyComponent
? { 0: UnwrapComponent<TLazyComponent> }[TLazyComponent extends any
? 0
: never]
: "WrappedComponent" extends keyof T
// @ts-ignore
? T["WrappedComponent"]
? {
// @ts-ignore
0: UnwrapComponent<T["WrappedComponent"]>;
// @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<T>` type to unwrap
* a single layer at a time.
*/
export type UnwrapComponent<T> = _UnwrapComponent<
_UnwrapComponent<
_UnwrapComponent<
_UnwrapComponent<
_UnwrapComponent<
_UnwrapComponent<_UnwrapComponent<_UnwrapComponent<T>>>
>
>
>
>
>;