Dev Helpers
← Back

Copy a mutable working list from an iterable

Copy a mutable working list from an iterable using TypeScript.

Open this example in the interactive library

Source code

type Item = Readonly<{ id: number; label: string }>;
const items: readonly Item[] = [
  { id: 1, label: "one" },
  { id: 2, label: "two" },
];
console.log(
  (<T,>(source: Iterable<T>): T[] => Array.from(source))(items).map(
    (item) => item.label,
  ),
);

Sample output

[ 'one', 'two' ]