arktype icon indicating copy to clipboard operation
arktype copied to clipboard

Morph intersection in chained object inferred as never

Open ssalbdivad opened this issue 1 year ago • 0 comments

This is a likely candidate for a bug in TS, though more investigation is needed. The b key following expression is incorrectly inferred as never:

const myType = type({
  a: ["string", "=>", (s) => s.length],
}).and({
  // this leads to b in the final type being inferred as never
  b: [{ b: "boolean" }, "=>", (b) => b],
});

// if the type is defined separately, the inference works,
// meaning the bug is likely in TS
const b = type({ b: "boolean" }, "=>", (b) => b);

// final type is correctly inferred here
const myType = type({
  a: ["string", "=>", (s) => s.length],
}).and({
  b,
});

ssalbdivad avatar Jun 23 '23 03:06 ssalbdivad