graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.58k stars 570 forks source link

TypeScript regression: loadOne no longer inferring types #2093

Closed benjie closed 3 months ago

benjie commented 3 months ago

See: https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwgOxgUwB4wDRwA2EAhgCYDyamBhwAzvAL5wBmUEIcARAOZQlWJRtwDcAKFCRYiOAHVgMABYAFXgGE6mDHBbtOPAAJkSMEmEIk0AejC8x48WUzJLUTHF7EARiUKJxODhrazhMejoMAFoyBhJvQkwo6lwoyI9DGABPMHDkKGAwGCjwyJhrNAhkkhBwsBJkTEC4NBq6ho8AcQEhRgCgoOAMTCghRrh1dCxcfoGgjggYNU1gbRgALnlFVQ0tDAk5pmajo-FUND7kGGw4AF4UKZwYAAoASglzvoX4e6vsADpeJgXtxvss9jBuO9gqEAILIRr0egAZSwYAAPAplODVhgAHxndB9AAkWD692I5ComGedEYzwA2t8ALqvAhoACuhEI7K5PLgwiyaGQcGeECK9Fedzxs1Y0FFn3g4qVrDgyslsyCITmAwAegB+ZpBRVwMG7XE-NVFBkABmZBwG2r1hqCR3mwI5UDQcAZ9vETHe4iAA

Reported by @purge

import { context, loadOne, list } from "grafast";
import { WithPgClient } from "@dataplan/pg";

declare global {
  // eslint-disable-next-line @typescript-eslint/no-namespace
  namespace Grafast {
    interface Context {
      rootPgClient: WithPgClient;
    }
  }
}

const ctx = context();
const root = ctx.get("rootPgClient"); // AccessStep<WithPgClient>
const $test = loadOne(list([root]), async (opts) => {
  for (const opt of opts) {
    //       ^? opt: unknown < Should be `UnwrapPlanTuple<...>`
    const rootPgClient = opt[0];
    //    ^? rootPgClient: any < Should be WithPgClient
  }
  return [];
});
benjie commented 3 months ago

(This was working fine in previous releases of Grafast, in particular beta.8 I think worked.)