I am looking to create a TypeScript type that will suggest certain object keys in the editor, while still allowing users to define arbitrary keys if they wish. Here is the type I have defined:
type SuggestedProperties = 'click' | 'change' | 'blur' | string;
The preferred properties are: 'click' | 'change' | 'blur'
(but I want to allow any string
as well).
type SuggestedKeysType = Partial<{ [key in SuggestedProperties]: any }>;
Now my goal is for the editor to automatically list these keys: 'click' | 'change' | 'blur'
when working with this code.
Is this achievable? Is my example accurate? Tested on Visual Studio Code / stackblitz: