#Extend type containing [key:string]: any
1 messages ยท Page 1 of 1 (latest)
what exactly do you mean by "extend"? like you want to add additional (more specific) properties?
also what does this mean?
I lose all the other properties from this type
can you show an example including this problem?
More or less, but this is the same ( ig ? )
I want to replace a property from this type
Yep wait
export interface ComponentProperties {
type?: string;
tagName?: string;
attributes?: Record<string, any>;
name?: string;
removable?: boolean;
draggable?: boolean | string | DraggableDroppableFn;
droppable?: boolean | string | DraggableDroppableFn;
badgable?: boolean;
stylable?: boolean | String[];
unstylable?: String[];
highlightable?: boolean;
copyable?: boolean;
resizable?: boolean | ResizerOptions;
editable?: boolean;
layerable?: boolean;
selectable?: boolean;
hoverable?: boolean;
locked?: boolean;
void?: boolean;
style?: any;
styles?: string;
content?: string;
icon?: string;
script?: string | ((...params: any[]) => any);
traits?: Traits;
propagate?: (keyof ComponentProperties)[];
toolbar?: ToolbarButtonProps[];
delegate?: ComponentDelegateProps;
components?: Components;
classes?: Selectors;
dmode?: DragMode;
"script-props"?: string[];
[key: string]: any;
}
Here is the type I want to extend
I mean, I want to replace the components property
But when I do that for example
export interface ServerComponentProperties extends Omit<ComponentProperties, 'components'> {
components?: ServerComponentProperties | ServerComponentProperties[];
}
Then it says ServerComponentProperties.classes is any
and any property other than components becomes any after I extended the base type
I guess it is because of the [key: string]: any property but it might be something else idk
is that index signature desirable in your final type?
Not really, I don't really care if it's there or not
I just need to access the other properties correctly
it's a bit funky, but you can first remove the index signature like this: