Skip to content

Commit b2f1a52

Browse files
committed
a (maybe) better way to type second argument of useUIExtension()
1 parent 39e8aff commit b2f1a52

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_ui_extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import { UIExtensionPoint, UIExtensionsStorage } from '../../../../common/types/
1010
export const UIExtensionsContext = React.createContext<UIExtensionsStorage>({});
1111

1212
type SpecificExtensionPoint<A, T, V> = A extends { type: T; view: V } ? A : never;
13+
type NarrowViews<T = UIExtensionPoint['type'], A = UIExtensionPoint> = A extends {
14+
type: T;
15+
}
16+
? A
17+
: never;
1318

1419
export const useUIExtension = <
1520
T extends UIExtensionPoint['type'] = UIExtensionPoint['type'],
16-
V extends UIExtensionPoint['view'] = UIExtensionPoint['view']
21+
V extends NarrowViews<T>['view'] = never
1722
>(
1823
integration: UIExtensionPoint['integration'],
1924
type: T,

0 commit comments

Comments
 (0)