<?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: Jonas de Abreu Resenes</title>
    <description>The latest articles on DEV Community by Jonas de Abreu Resenes (@jabreuar).</description>
    <link>https://dev.to/jabreuar</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%2F1712338%2Fec1e22ad-f0fb-4c35-94aa-225b2dffa862.png</url>
      <title>DEV Community: Jonas de Abreu Resenes</title>
      <link>https://dev.to/jabreuar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jabreuar"/>
    <language>en</language>
    <item>
      <title>Prefer utility types over model changes in TypeScript</title>
      <dc:creator>Jonas de Abreu Resenes</dc:creator>
      <pubDate>Mon, 08 Jul 2024 19:49:39 +0000</pubDate>
      <link>https://dev.to/jabreuar/prefer-utility-types-over-model-changes-in-typescript-61a</link>
      <guid>https://dev.to/jabreuar/prefer-utility-types-over-model-changes-in-typescript-61a</guid>
      <description>&lt;p&gt;Generally, in software, a model is an abstraction or a way to represent a system, process, or object in the real world. Modeling is the process of creating these abstractions to facilitate understanding, analysis, and design of system. &lt;/p&gt;

&lt;p&gt;TypeScript provides several utility types to facilitate common type transformations, these utilities are available globally and can be used to avoid changing the nature of a model definition. Some of these utilities aim developers to keep their models consistency and you must use them rather than creating a new model to represent the variants of an existing entity in your code base. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Pick&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may use a &lt;em&gt;Pick&lt;/em&gt; when you want to construct a "light version" of an existing model, for instance, you want to represent a summary of an user model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface User {
  firstName: string;
  lastName: string;
  age: number;
  dateOfBirth: string;
  primaryEmail: string;
  secondaryEmail: string;
}

type UserBasicInfo = Pick&amp;lt;User, "firstName" | "lastName"&amp;gt;;

const userBasicInfo: UserBasicInfo = {
  firstName: "Jonas",
  lastName: "Resenes",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The Omit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;em&gt;Omit&lt;/em&gt; is in the same "family" as the &lt;em&gt;Pick&lt;/em&gt;, prefer &lt;em&gt;Omit&lt;/em&gt; over &lt;em&gt;Pick&lt;/em&gt; when you are composing a new type with a consider number of fields from an existing model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface User {
  firstName: string;
  lastName: string;
  age: number;
  dateOfBirth: string;
  primaryEmail: string;
  secondaryEmail: string;
}

type UserPreview = Omit&amp;lt;User, "primaryEmail" | "secondaryEmail"&amp;gt;;

const userPreview: UserPreview = {
  firstName: "Jonas",
  lastName: "Resenes",
  age: 36,
  dateOfBirth: "08/21/1987"
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
