I'm curious as to why this inheritance model succeeds between a base and child, but fails between a child and grandchild. I'm sure there is something I've missed here. The error would make sense to me, if only it also occurred between base and child.
type BaseType = {
base: true,
...
}
type fnType<O: BaseType> = (options: O) => void;
const base = (options: BaseType) => {
return;
}
function extend<T: BaseType>(parent: fnType<T>): fnType<T>{
return (options: T): void => {
return parent(options);
}
}
type ChildOneType = {
...BaseType,
one: true,
...
};
const childOne = extend<ChildOneType>(base);
type ChildTwoType = {
...ChildOneType,
two: true,
...
};
// why fail?
// ---
// Cannot call `extend` with `childOne` bound to `parent` because property `two`
// is missing in `ChildOneType` [1] but exists in `ChildTwoType` [2] in type
// argument `O` [3]. [prop-missing]
const childTwo = extend<ChildTwoType>(childOne);