1
type a = { a: 1, [index: string]: any , name:string, b?:boolean}
type b = Omit<a,'a'> //b is {[index: string]:any}

playground

type b would be {[index: string]:any}, but I expect it to be {[index: string]: any , name:string, b?:boolean}

why is this happening?

Marius Jaraminas
  • 813
  • 1
  • 7
  • 19
Acid Coder
  • 2,047
  • 15
  • 21

1 Answers1

1

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}

playground

Marius Jaraminas
  • 813
  • 1
  • 7
  • 19
Acid Coder
  • 2,047
  • 15
  • 21