I am importing an interface called WidgetProps from a library to use it as base for other types. Such an interface looks exactly like this:
export interface WidgetProps
extends Pick<
React.HTMLAttributes<HTMLElement>,
Exclude<keyof React.HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus'>
> {
id: string;
schema: JSONSchema7;
uiSchema: UiSchema;
value: any;
required: boolean;
disabled: boolean;
readonly: boolean;
autofocus: boolean;
placeholder: string;
onChange: (value: any) => void;
options: NonNullable<UiSchema['ui:options']>;
formContext: any;
onBlur: (id: string, value: any) => void;
onFocus: (id: string, value: any) => void;
label: string;
multiple: boolean;
rawErrors: string[];
registry: Registry;
[prop: string]: any; // Allow for other props
}
However, when omitting keys using the Omit utility I am not getting any autocompletion nor TS warnings/errors when assigning the new type to a variable.
type ValidWidgetProps = Omit<
WidgetProps,
| 'autofocus'
| 'formContext'
| 'options'
| 'rawErrors'
| 'readonly'
| 'registry'
| 'schema'
| 'uiSchema'
>
const a: ValidWidgetProps = {
// there's no suggestions or errors here
anyKey: 'some value'
}
I noticed that, when removing the last key (which opens the interface for any other property) [prop: string]: any
, Omit
works as expected. This is probably normal TS behavior, but I would like to remove that last one without having to clone the whole interface into my code like I did to prove this was causing the error.
Is there a way to remove it? I am using TS 4.5.5
. The interface is from the react-json-schema-form
lib.