Dev Helpers
← Back

Check for dangling dependency names

Check for dangling dependency names. Start with typed records and inspect the inferred result.

Open this example in the interactive library

Source code

type Row = { task: string; needs: string[] };
const rows: Row[] = [
  { task: "design", needs: [] },
  { task: "build", needs: ["design"] },
  { task: "test", needs: ["build"] },
  { task: "ship", needs: ["build", "test"] },
];
const result = [...new Set(rows.flatMap((r) => r.needs))].filter(
  (name) => !rows.some((r) => r.task === name),
);
console.log(JSON.stringify(result, null, 2));

Sample output

[]