1

Suppose there is the following interfaces and function:

export interface Parent {
  [argument: string]: unknown;
}

interface Child extends Parent {
  something: number;
  name: string;
}

function func(foo: Omit<Child, 'name'>): number {
  return foo.something;
}

TypeScript complains that Type 'unknown' is not assignable to type 'number'.. I sorta kinda understand why this is, but I'm not sure how to overcome it to achieve what I want (aka for foo to be the same type as Child but with name not required).

Note that I don't have access to change neither Child nor Parent.

Any help would be appreciated, thanks!

Richard Robinson
  • 867
  • 1
  • 11
  • 38
  • 1
    [An answer to the other question](https://stackoverflow.com/a/54827898/2887218) shows how to write a version of `Omit` that behaves the way you want here. Translating that to your example code yields [this](https://tsplay.dev/w8vYdm). – jcalz Mar 31 '21 at 02:52

0 Answers0