You may answer "interface A extends B { ... }" right away when you see the title, but that is not what I want.
I mean, I have two types (e.g. A and B), and I want to get a type C, which has all members of A and the members of B that have different names from members of A, and the types of members of A should can be assigned to those of B.
All of this is the same as the behavior of interface A extends B { ... }
, except that it must be obtained by type formula.
In other words, I want something like this:
interface C extends B {
[K in keyof A]: A[K];
// this is invalid because members of interfaces must be statically determined in TS
}
// And I don't want an interface.
or like this:
// About Omit:
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type
type C = Omit<B, keyof A> & A;
// this can be invalid when B has
// [k: string]: any;
I want to know if I could get type C in the following form:
type A = { ... }
type B = { ... }
type C = A formula containing A and B