79320569

Date: 2024-12-31 18:15:46
Score: 1.5
Natty:
Report link

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
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Redskinsjo