I created a function to strip an object of an interface. However Typescript (Version 3.2.2) now claims the type is never when it should be a type with property child
interface Child extends Parent {
child: string
}
interface Parent {
parent: string
}
const a: Child = { child: "", parent: "" }
const b = removeParent(a);
function removeParent<T extends Parent>(obj: T) {
delete obj.parent;
return obj as Exclude<T, Parent>;
}
// b is now type never...
This does work:
function removeParent<T extends Parent>(obj: T) {
delete obj.parent;
type Without<T, K> = Pick<T, Exclude<keyof T, K>>;
return obj as Without<T, "parent">;
}
However I want a generic solution that doesn't require me writing out the types to exclude.