I am trying to construct a typing for an object where for property key "_vars" it must be a Record<string, any>
, but for all other property keys (that are not "_vars"), it must be a string.
Something like this:
interface XY {
_vars?: Record<string, any>;
[k:string]: string; // should exclude _vars
}
But the above doesn't work, reporting TS error: Property '_vars' of type 'Record<string, any> | undefined' is not assignable to 'string' index type 'string'
Is there any way this can be achieved in Typescript?
Thanks in advance!