refactor(ui): remove never-typed ghost props from useDefinition ownProps
Replace the ChildrenProps intersection approach with ResolveBgProps, which transforms the base type so that only the relevant children variant exists in the final type. Provider components get childrenWithBgProvider (with children Omit'd), non-providers pass through unchanged — no more optional never properties showing up in autocomplete. Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/ui': patch
|
||||
---
|
||||
|
||||
Cleaned up `useDefinition` `ownProps` types to remove never-typed ghost properties from autocomplete.
|
||||
@@ -81,10 +81,19 @@ type ResolvedOwnProps<
|
||||
[K in keyof PropDefs & keyof P]: ResolvePropType<P[K], PropDefs[K]>;
|
||||
};
|
||||
|
||||
type ChildrenProps<Bg extends 'provider' | 'consumer' | undefined> =
|
||||
Bg extends 'provider'
|
||||
? { childrenWithBgProvider: ReactNode; children?: never }
|
||||
: { children: ReactNode; childrenWithBgProvider?: never };
|
||||
type BaseOwnProps<
|
||||
D extends ComponentConfig<any, any>,
|
||||
P extends Record<string, any>,
|
||||
> = {
|
||||
classes: Record<keyof D['classNames'], string>;
|
||||
} & ResolvedOwnProps<P, D['propDefs']>;
|
||||
|
||||
type ResolveBgProps<
|
||||
D extends ComponentConfig<any, any>,
|
||||
TBase,
|
||||
> = D['bg'] extends 'provider'
|
||||
? Omit<TBase, 'children'> & { childrenWithBgProvider: ReactNode }
|
||||
: TBase;
|
||||
|
||||
type DataAttributeKeys<PropDefs> = {
|
||||
[K in keyof PropDefs]: PropDefs[K] extends { dataAttribute: true }
|
||||
@@ -122,10 +131,7 @@ export interface UseDefinitionResult<
|
||||
D extends ComponentConfig<any, any>,
|
||||
P extends Record<string, any>,
|
||||
> {
|
||||
ownProps: {
|
||||
classes: Record<keyof D['classNames'], string>;
|
||||
} & ResolvedOwnProps<P, D['propDefs']> &
|
||||
ChildrenProps<D['bg']>;
|
||||
ownProps: ResolveBgProps<D, BaseOwnProps<D, P>>;
|
||||
|
||||
// Rest props excludes both propDefs keys AND utility prop keys
|
||||
restProps: keyof Omit<P, keyof D['propDefs'] | UtilityKeys<D>> extends never
|
||||
|
||||
Reference in New Issue
Block a user