Reputation: 2747
type a = { a: 1, [index: string]: any , name:string, b?:boolean}
type b = Omit<a,'a'> //b is {[index: string]:any}
type b would be {[index: string]:any}
, but I expect it to be {[index: string]: any , name:string, b?:boolean}
why is this happening?
Upvotes: 1
Views: 92
Reputation: 2747
I found the solution and explanation in this thread
type a = { a: 1, [index: string]: any , name:string, b?:boolean}
declare type _removeIndexSignature<T> = Pick<
T,
{
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U }
? U
: never>
type b = _removeIndexSignature<a> //{ a: 1, name:string, b?:boolean}
Upvotes: 1