<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mathias Nielsen</title>
    <description>The latest articles on DEV Community by Mathias Nielsen (@vanquard).</description>
    <link>https://dev.to/vanquard</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F469423%2Ff3230976-e828-43dd-ba08-761d318ea36b.png</url>
      <title>DEV Community: Mathias Nielsen</title>
      <link>https://dev.to/vanquard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vanquard"/>
    <language>en</language>
    <item>
      <title>Deploying a (static) Vite React app</title>
      <dc:creator>Mathias Nielsen</dc:creator>
      <pubDate>Thu, 14 Nov 2024 08:09:32 +0000</pubDate>
      <link>https://dev.to/cph-business-web-dev/deploying-a-static-vite-react-app-4aen</link>
      <guid>https://dev.to/cph-business-web-dev/deploying-a-static-vite-react-app-4aen</guid>
      <description>&lt;p&gt;So there's probably already a ton of blog posts out there on this subject, even this is a follow up to my own previous &lt;a href="https://dev.to/vanquard/deploying-a-static-create-react-app-e7i"&gt;post&lt;/a&gt; on the same topic.&lt;/p&gt;

&lt;p&gt;Things have changed since CRA was the recommended way of scaffolding react projects, and full-stack frameworks like NextJS/Remix is the new way to do it.&lt;/p&gt;

&lt;p&gt;But i still want to have an opportunity to keep things a bit more simple than a full NextJS project, so I have a Vite scaffolded React project, with TanStack Router, and here's how to get it deployed to GitHub Pages.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The steps are almost the same as the previous post, with a few changes&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 1: npm package
&lt;/h2&gt;

&lt;p&gt;To make it easy, we're using an npm package called "gh-pages".&lt;/p&gt;

&lt;p&gt;Install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Homepage
&lt;/h2&gt;

&lt;p&gt;Github Pages follows a pattern for your url (if you're using the default one given by Github): &lt;code&gt;your-github-username.github.io/your-repo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Following this pattern, add a "Homepage" attribute to your package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;{
  "name": "business-card",
  "version": "0.1.0",
&lt;span class="gi"&gt;+  "homepage": "https://username.github.io/repo",
&lt;/span&gt;  "private": true,
  "dependencies": {...},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My link would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"homepage"&lt;/span&gt;: &lt;span class="s2"&gt;"https://cph-mtnl.github.io/business-card"&lt;/span&gt;,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Routing
&lt;/h2&gt;

&lt;p&gt;Since we're now adding a base route to our routing, (compared to working on localhost), we need to add this base route to our vite and routing config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// File: vite.config.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TanStackRouterVite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@tanstack/router-plugin/vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// https://vite.dev/config/&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/business-card&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;TanStackRouterVite&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And our &lt;code&gt;TanStack Router: RouterProvider&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;RouterProvider&lt;/span&gt;
  &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;basepath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/business-card&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Scripts
&lt;/h2&gt;

&lt;p&gt;Also in your package.json, we need to add 2 scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;  "scripts": {
&lt;span class="gi"&gt;+    "predeploy": "npm run build",
+    "deploy": "gh-pages -d dist",
&lt;/span&gt;    ...
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Deploy
&lt;/h2&gt;

&lt;p&gt;Lastly we need to run the deploy command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Done
&lt;/h2&gt;

&lt;p&gt;Or at least, that should be it, if you're having problems, and cannot see it, make sure these two things are as it should be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit your repo on GitHub, and go to Settings and then Pages.
And then you should see:
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbftdz86619coxdun1yy.png" alt="successful deploy" width="800" height="77"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If not, make sure you've chosen the gh-pages branch:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9gyusfyzrfb5kjjl50a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9gyusfyzrfb5kjjl50a.png" alt="show branch" width="800" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deploying a (static) create-react-app</title>
      <dc:creator>Mathias Nielsen</dc:creator>
      <pubDate>Fri, 25 Feb 2022 10:35:35 +0000</pubDate>
      <link>https://dev.to/vanquard/deploying-a-static-create-react-app-e7i</link>
      <guid>https://dev.to/vanquard/deploying-a-static-create-react-app-e7i</guid>
      <description>&lt;p&gt;So there's probably already a ton of blog posts out there on this subject.&lt;br&gt;
But I've been trying to get a nice and easy way to deploy my create-react-app (CRA) to Github Pages, and I finally found out how to! I found a guide, but it seemed overly complicated, so now I wanted to make a simple guide/blog post about it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: npm package
&lt;/h2&gt;

&lt;p&gt;To make it easy, we're using an npm package called "gh-pages".&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I won't go into detail about this package, but its mentioned by CRAs own documentation, so I trust it.&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Homepage
&lt;/h2&gt;

&lt;p&gt;Github Pages follows a pattern for your url (if you're using the default one given by Github):&lt;br&gt;
&lt;code&gt;your-github-username.github.io/your-repo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Following this pattern, add a "Homepage" attribute to your package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;{&lt;/span&gt;
  "name": "business-card",
  "version": "0.1.0",
&lt;span class="gi"&gt;+  "homepage": "https://username.github.io/repo",
&lt;/span&gt;  "private": true,
  "dependencies": {...},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Scripts
&lt;/h2&gt;

&lt;p&gt;Also in your package.json, we need to add 2 scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;  "scripts": {
&lt;span class="gi"&gt;+    "predeploy": "npm run build",
+    "deploy": "gh-pages -d build",
&lt;/span&gt;    ...
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Deploy
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Done
&lt;/h2&gt;

&lt;p&gt;Or at least, that should be it, if you're having problems, and cannot see it, make sure these two things are as it should be:&lt;br&gt;
Visit your repo on GitHub, and go to Settings and then Pages.&lt;br&gt;
And then you should see:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uemJExaW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbftdz86619coxdun1yy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uemJExaW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbftdz86619coxdun1yy.png" alt="successful deploy" width="880" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If not, make sure you've chosen the gh-pages branch:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--05u3Ku6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9gyusfyzrfb5kjjl50a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--05u3Ku6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9gyusfyzrfb5kjjl50a.png" alt="show branch" width="880" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats:
&lt;/h2&gt;

&lt;p&gt;There's 2 caveats I am currently aware of.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You need to do some slight changes if you want to deploy a user page&lt;/li&gt;
&lt;li&gt;If you are using routing in your react app, you need to use hash routes instead.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>githubpages</category>
    </item>
    <item>
      <title>Minimal create-react-app</title>
      <dc:creator>Mathias Nielsen</dc:creator>
      <pubDate>Fri, 25 Feb 2022 08:48:06 +0000</pubDate>
      <link>https://dev.to/vanquard/basic-create-react-app-1g48</link>
      <guid>https://dev.to/vanquard/basic-create-react-app-1g48</guid>
      <description>&lt;h2&gt;
  
  
  The problem:
&lt;/h2&gt;

&lt;p&gt;When I start a new create-react-app (CRA), it has a lot of files and stuff I don't need. This includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;reportWebVitals&lt;/code&gt;(Analytics and performance, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;logo.svg&lt;/code&gt; and some other stuff to create the React "Hello World" app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setupTests.js&lt;/code&gt;, and other test related defaults.
Although I might be yelled at for saying: "I don't need testing", I just don't need it for smaller prototype setups.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;When I tried to research for a solution for this problem (fancy way of saying, I googled it), I encountered a post on Stackoverflow, and I am obviously not the only one with this problem, so a guy from CRA (if I remember correctly), commented and mentioned they have developed &lt;code&gt;templates&lt;/code&gt; to satisfy users which had a different workflow than the default one.&lt;br&gt;
And that I could find all the templates available on npm, simply by searching for &lt;a href="https://www.npmjs.com/search?q=cra-template-*"&gt;cra-template-*&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here I found the &lt;a href="https://www.npmjs.com/package/cra-template-minimal"&gt;template I was looking for&lt;/a&gt; and can now create my simple and basic CRA Apps, simply by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app my-app &lt;span class="nt"&gt;--template&lt;/span&gt; minimal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>TIL about specific Array combination types</title>
      <dc:creator>Mathias Nielsen</dc:creator>
      <pubDate>Thu, 25 Nov 2021 21:43:22 +0000</pubDate>
      <link>https://dev.to/vanquard/til-about-specific-array-combination-types-28bo</link>
      <guid>https://dev.to/vanquard/til-about-specific-array-combination-types-28bo</guid>
      <description>&lt;p&gt;Okay, so its not actually called "specific Array combination types", but that was the best description I had for it, before I looked it up.&lt;br&gt;
Its actually called "Tuple Types" and the documentation can be found here: &lt;a href="https://www.tutorialsteacher.com/typescript/typescript-tuple"&gt;https://www.tutorialsteacher.com/typescript/typescript-tuple&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'll come back to why this blew my mind today, but first, lets scroll back a bit, to some of my first steps into JS/TS programming. I started my programming career in Java, and one of the things that annoyed the hell out of me, was the fact that I could only have 1 object returned from a function (This was before the Pair class was introduced).&lt;/p&gt;

&lt;p&gt;But in JS we can easily just return an array with 2 values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mathias&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And combined with some destructuring on the recieving, it was all nice and easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myAge&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding types
&lt;/h2&gt;

&lt;p&gt;Until today I never had to add types onto a scenario like this, usually when I work with arrays, I either just do a basic &lt;code&gt;string[]&lt;/code&gt;, or when its required in complex object scenarios: &lt;code&gt;Array&amp;lt;{name: string, age: number}&amp;gt;&lt;/code&gt;.&lt;br&gt;
But with the tuples we can actually avoid naming them and just say the return type for our function is &lt;code&gt;[string, number]&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mathias&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Vue relation
&lt;/h2&gt;

&lt;p&gt;I came across this when I working with Vue2 combined with TS, and was trying to create a v-for loop over a Map, but Vue2 did not support this, so I had to come up with a different approach that supported the same end goal.&lt;/p&gt;

&lt;p&gt;So this is where the new tuples came in handy! Given an example with some data in a Map:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lots of data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;more data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I could then destructure it into an array like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Yielding:&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;key1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lots of data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;key2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;more data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in order to Type this we now have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;asArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading this far, hope you gained something from this post.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
