Your implementation seems overkill.
If you remove PureType
and Types
, you can succeed in getting out of this without error. Is this fitting your need ?
type Core = { type: "core-1" } | { type: "core-2" };
type AnyTypedObject = { type: string } | { [key: string]: any };
type TypedObject<B extends AnyTypedObject> = B | Core;
function foo<B extends AnyTypedObject>(input: TypedObject<B>) {
return input;
}
foo<{ url: "/about" }>({ url: "/about" }); // okay
foo<{ url: "/about" }>({ url: "okok" }); // fails as intended
foo<{ url: "/about" }>({ uri: "/about" }); // fails as intended