Creating a Typescript Javascript Array with 10 Undefined Items

Ole Ersoy
Jul 8, 2023

--

Scenario

We want a typescript array with 10 undefined items that we can map over.

Approach

const a: undefined[] = Array.from(Array(10));
console.log(a);
const b: 1[] = a.map((i) => 1);
console.log(b);

Demo

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet