<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[All Things Typescript: Mid-week Scoop]]></title><description><![CDATA[A mid-week scoop that will cover a single short topic in Typescript for discussion]]></description><link>https://www.allthingstypescript.dev/s/all-things-typescript-mid-week-scoop</link><image><url>https://substackcdn.com/image/fetch/$s_!5AXN!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7922083f-3e29-485a-ab34-3b07ac80034c_1084x1084.png</url><title>All Things Typescript: Mid-week Scoop</title><link>https://www.allthingstypescript.dev/s/all-things-typescript-mid-week-scoop</link></image><generator>Substack</generator><lastBuildDate>Sun, 05 Apr 2026 22:52:04 GMT</lastBuildDate><atom:link href="https://www.allthingstypescript.dev/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Maina Wycliffe]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[allthingstypescript@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[allthingstypescript@substack.com]]></itunes:email><itunes:name><![CDATA[Maina Wycliffe]]></itunes:name></itunes:owner><itunes:author><![CDATA[Maina Wycliffe]]></itunes:author><googleplay:owner><![CDATA[allthingstypescript@substack.com]]></googleplay:owner><googleplay:email><![CDATA[allthingstypescript@substack.com]]></googleplay:email><googleplay:author><![CDATA[Maina Wycliffe]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Mid-week scoop - where do you look for types for third party libraries on NPM?]]></title><description><![CDATA[In this week's mid-week scoop, I explain to developers where to look for types when consuming third-party libraries in Typescript.]]></description><link>https://www.allthingstypescript.dev/p/mid-week-scoop-where-do-you-look</link><guid isPermaLink="false">https://www.allthingstypescript.dev/p/mid-week-scoop-where-do-you-look</guid><dc:creator><![CDATA[Maina Wycliffe]]></dc:creator><pubDate>Wed, 05 Oct 2022 12:45:45 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/h_600,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey, Wycliffe here, and welcome to this week&#8217;s mid-week scoop.</p><p>Every week, either Wednesday or Thursday, I will do a more compact scoop on different Typescript-related topics and practices to help you understand Typescript even better. </p><p>I also send out deep dives content every Monday, where I cover more complex concepts such as <a href="https://www.allthingstypescript.dev/p/how-to-overload-functions-in-typescript">how to Overload Functions</a> in Typescript. </p><p>Please consider subscribing to this free newsletter if you haven&#8217;t, and share it with friends if you already have.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.allthingstypescript.dev/subscribe?"><span>Subscribe now</span></a></p><p>Thank you.</p><div><hr></div><p>One thing I usually love doing when looking for NPM packages to use is to try and figure out if it&#8217;s written in Typescript or not. Why? Because it can be excruciating using a third-party dependency without the benefits of type declarations for the libraries - type safety, easy to look up documentation for code, and auto-completion (IntelliSense) in your favorite editor.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6Ryx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6Ryx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 424w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 848w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 1272w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6Ryx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png" width="1456" height="1112" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/afeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1112,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:176890,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6Ryx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 424w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 848w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 1272w, https://substackcdn.com/image/fetch/$s_!6Ryx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fafeefb65-ea19-4416-94e4-95bf65916a8e_1608x1228.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I do this because most Javascript libraries written in Typescript will usually ship with their declaration files. Code editors will automatically pick this for autocompletion/IntelliSense while Typescript and Linters for type checking and linting. Once you have installed the npm package, you don&#8217;t have to do anything extra concerning the library types.</p><p>What if it&#8217;s written in plain Javascript? Libraries written in plain Javascript can still ship their types if the maintainers want, but it&#8217;s not very common to see that, so in this case, the next place to look for types is <a href="https://www.typescriptlang.org/dt/">DefinetlyTyped</a>.</p><blockquote><p><strong>Please note:</strong> it also possible to find a library written in Typescript, that doesn&#8217;t ship with it&#8217;s type declarations.</p></blockquote><h2>The DefinitelyTyped Project</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fxYm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fxYm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 424w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 848w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 1272w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fxYm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png" width="1007" height="356" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:1007,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106686,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fxYm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 424w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 848w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 1272w, https://substackcdn.com/image/fetch/$s_!fxYm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F61b2360b-767f-4fd7-a533-de664d3a9571_1007x356.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>DefintelyTyped is a community-driven project for a central place where types for popular javascript libraries can be found. The community (not necessarily the authors) contributes to the type declaration for libraries which are then made available to everyone via NPM. Everything is scoped under the <code>@types</code> name, and if you, for instance, were interested in express types, you would install <code>@types/express</code> with the name of the library being the package name. Once you have installed the above express types, Typescript will pick them up automatically to type-check your code.</p><blockquote><p><strong>Please Note:</strong> The Typescript language service is usually clever enough to determine that an npm package you are using doesn&#8217;t have any declaration files shipped. It will usually suggest that you install the types from DefinitelyTyped if available.</p></blockquote><p>Unlike types that ship with libraries, DefinetlyTyped types are shipped independently of the libraries they provided types for. This means you need to be aware of this and ensure that you have type compatibility between the installed version of the  library and its types from definitely typed. If you are not careful, you might end up in a situation where your code type-checks correctly, but there are bugs at runtime since the source of the types you have is not for the version of the library you have installed.</p><h3>Defining your types for Libraries</h3><p>Suppose you can&#8217;t find the types for a library you are using in the DefinitelyTyped project. This happens when a project doesn&#8217;t have a lot of users; hence not enough people to contribute to the type declaration for the package. </p><p>In that case, you might consider creating type declarations for the library you are consuming locally. If you find yourself in this situation, please contribute; someone else will appreciate it and help improve your work so that we can all benefit.</p><p>You can achieve this by creating your ambient declaration files within your project. These files have an extension <code>.d.ts</code> and are a way of informing the typescript compiler that something library exists at runtime or some library has certain types. </p><p>This is going to be the topic I am going to explore next week on Monday. Please subscribe not to miss out.</p><div><hr></div><p>And that&#8217;s it from me, I hope you enjoyed &#10084;&#65039; this issue as much as I did writing it, and I hope you have a fantastic week ahead. </p><p>Please consider doing one of the following things if you love this issue.</p><p><strong>1. Share it &#10084;&#65039; </strong>- Help me spread word of mouth and help All Things Typescript grow:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/p/mid-week-scoop-where-do-you-look?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://www.allthingstypescript.dev/p/mid-week-scoop-where-do-you-look?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><strong>2. &#9993;&#65039; Subscribe to this newsletter. </strong>You will receive weekly content like this from <strong>All Things Typescript</strong> that will help you learn and master Typescript.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://www.allthingstypescript.dev/subscribe?"><span>Subscribe now</span></a></p><p><strong>3. Consider Sponsoring me on GitHub &#10084;&#65039;; </strong>you will be helping me create more free content for the benefit of everyone.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://github.com/sponsors/mainawycliffe&quot;,&quot;text&quot;:&quot;Please consider sponsoring me &#10084;&#65039;&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://github.com/sponsors/mainawycliffe"><span>Please consider sponsoring me &#10084;&#65039;</span></a></p><p><strong>Au revoir &#128075;&#127999;.</strong></p>]]></content:encoded></item><item><title><![CDATA[Mid-week Scoop: Comparing Functions in Typescript]]></title><description><![CDATA[Taking a look at how Typescript compares functions to check whether one function type is assignable to another function Type.]]></description><link>https://www.allthingstypescript.dev/p/mid-week-scoop-comparing-functions</link><guid isPermaLink="false">https://www.allthingstypescript.dev/p/mid-week-scoop-comparing-functions</guid><dc:creator><![CDATA[Maina Wycliffe]]></dc:creator><pubDate>Thu, 08 Sep 2022 05:58:57 GMT</pubDate><enclosure url="https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/001c6cf5-8109-4b81-bc1f-259673533a30_1280x720.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In a <a href="https://www.allthingstypescript.dev/p/if-it-looks-like-a-duck-walks-like">previous issue</a>, I looked into structural typing in Typescript but focussed on object literals mostly (you can find the previous article <a href="https://www.allthingstypescript.dev/p/if-it-looks-like-a-duck-walks-like">here</a>). In this scoop, I want to look closely at something closely related to structural typing in Typescript and how comparing functions works in Typescript. </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading All Things Typescript! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>So, without further ado:</p><p>So, how does Typescript compare two functions and determine whether they are assignable to each other? Let&#8217;s take the following function Types:</p><pre><code>type F1 = () =&gt; void;
type F2 = (input1: string) =&gt; void;</code></pre><p>In Typescript, we can assign a variable typed as <code>F2</code> above to <code>FI</code>, but not vice versa:</p><pre><code>
let f1: F1 = () =&gt; {
    console.log("F1")
}

// this is okay
let f2: F2 = f1;

// this will error
let f3: F1 = f2;
//   ^ Type 'F2' is not assignable to type 'F1'</code></pre><p>Why? In this case, typescript mirrors this behavior from Javascript, where it&#8217;s quite common to ignore extra parameters of functions when we are not using them. Remember, Typescript compiles to Javascript and adds a typing system (mostly) on top of the features that Javascript provides; this means mirroring some of the behavior from Javascript whenever it doesn&#8217;t compromise Type Safety.</p><blockquote><p>The reason for this assignment to be allowed is that ignoring extra function parameters is actually quite common in JavaScript. For example, <code>Array#forEach</code> provides three parameters to the callback function: the array element, its index, and the containing array. Nevertheless, it&#8217;s very useful to provide a callback that only uses the first parameter</p><p>Link to <a href="https://www.typescriptlang.org/docs/handbook/type-compatibility.html#comparing-two-functions">docs</a>.</p></blockquote><p>Typescript will not allow you to provide function parameter types that do not match the parameter types in each position. If we tried to do the opposite, assigning a function typed as <code>F2</code> to another function typed as <code>F1</code>, then Typescript will complain. </p><pre><code>let f1: F1 = () =&gt; {
    console.log("F1")
}

// this is okay
let f2: F2 = f1;

// this will error
let f3: F1 = f2;
//   ^ Type 'F2' is not assignable to type 'F1'</code></pre><p>With the <code>F2</code> type having a required input parameter - <code>input1</code> - it makes sense since the <code>F1</code> type doesn&#8217;t have any parameters. </p><h4>Optional Parameters</h4><p>If we made the <code>input1</code> parameter optional for the <code>F2</code> function, then typescript would stop complaining.</p><pre><code>type F1 = () =&gt; void;
type F2 = (input1?: string) =&gt; void;

let f1: F1 = () =&gt; {
    console.log("F1")
}

// this is okay
let f2: F2 = f1;

// this is okay now
let f3: F1 = f2;</code></pre><p>This behavior is also mirrored from Javascript behavior, and since optional parameters are undefined when they are not supplied/provided in Javascript, hence why Typescript allows this behavior. This behavior is unsound from a type-system perspective. Still, one that is allowed by the Typescript Type System, which has to take into account the runtime behavior of Javascript, and this is why the Typescript system is said to be unsound; I will explore this in a future issue. </p><h4>Conclusion</h4><p>In this week&#8217;s scoop, we covered structural typing in functions. Understanding this behavior is essential when writing and reading Typescript code, and it will help you form a much better mental model for what to expect from Typescript as you continue working with it.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading All Things Typescript! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Are you using Typescript strict Compiler Option?]]></title><description><![CDATA[I have a question for you, have you enabled the strict flag in your TS Config Compiler Option?]]></description><link>https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler</link><guid isPermaLink="false">https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler</guid><dc:creator><![CDATA[Maina Wycliffe]]></dc:creator><pubDate>Thu, 25 Aug 2022 09:49:35 GMT</pubDate><enclosure url="https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/4c67b26e-9a7e-4810-985a-40b352fb3533_1920x1200.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I have a question for you, have you enabled the strict flag in your TS Config Compiler Option? If not, why and would you consider enabling it in the future?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.allthingstypescript.dev/subscribe?"><span>Subscribe now</span></a></p><h4>What does the <code>strict</code> TS Config Compiler Option do? </h4><p>This single option enables stricter type checks of your Typescript codebase for much better Type safety. These options can be enabled and disabled for each individual option, but with the strict compiler option, you toggle all of them with a single compiler flag. </p><p>Another point to note about the <code>strict</code> compiler option is that future versions of Typescript may introduce stricter checking, and by using <code>strict</code> , you will be opting for those as well. Keep that in mind when upgrading to newer versions of Typescript.</p><h3>What compiler options does <code>strict </code>flag enable?</h3><ul><li><p><code>alwaysStrict - </code>This ensures that your TS files are parsed in the ECMAScript strict mode, and typescript will emit &#8220;use strict&#8221; for each source file after transpilation<code>.</code></p></li><li><p><code>strictNullChecks </code>- Ensures that null and undefined are treated as their own types instead of being effectively ignored. This forces you to handle any null or undefined values before being used.</p></li><li><p><code>strictBindCallApply </code>- It ensures that built-in methods of functions call, bind, and apply are called with the correct arguments for the underlying function.</p></li><li><p><code>strictFunctionTypes</code> - Ensures that function parameters are checked more strictly.</p></li><li><p><code>strictPropertyInitialization</code> - Ensure that class properties are set in the constructor.</p></li><li><p><code>noImplicitAny</code> - When false, typescript will implicitly infer some types as any when no annotations are present. Turning on this ensures you Typescript will implicitly infer a type as any which can compromise type safety as the <code>any</code> type can spill over to other areas of code quite easily. </p></li><li><p><code>noImplicitThis </code>- Throws an error when <code>this</code> expression is inferred as the <code>any</code> type.</p></li><li><p><code>useUnknownInCatchVariable </code>- Instead of using <code>any </code>for the type of an error inside the catch statement, Typescript will use unknown, allowing for a more comprehensive error handling.</p></li></ul><p>What do you think about the <code>strict</code> compiler option?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler/comments"><span>Leave a comment</span></a></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.allthingstypescript.dev/p/are-you-using-typescript-strict-compiler?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p>]]></content:encoded></item><item><title><![CDATA[Mid-week Scoop: Understanding Excess Property Checking in Typescript]]></title><description><![CDATA[Excess property checking is when Typescript checks your object to ensure that it doesn&#8217;t contain any extra properties on top of what is defined &#8230;]]></description><link>https://www.allthingstypescript.dev/p/mid-week-scoop-understanding-excess</link><guid isPermaLink="false">https://www.allthingstypescript.dev/p/mid-week-scoop-understanding-excess</guid><dc:creator><![CDATA[Maina Wycliffe]]></dc:creator><pubDate>Thu, 04 Aug 2022 12:57:46 GMT</pubDate><enclosure url="https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/6774ffef-9b97-499b-a2d2-b95497fa54ba_1920x1200.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Excess property checking is when Typescript checks your object to ensure that it doesn&#8217;t contain any extra properties on top of what is defined in the type annotation for the object.</p><p>Typescript doesn&#8217;t always check for excess properties in an object. Understanding when Typescript will check for excess properties is crucial as it helps you know what to expect from Typescript under different conditions.</p><p>Let&#8217;s start with the following type:</p><p><code>type Person {</code></p><p><code>  firstName: string;</code></p><p><code>  lastName: string;</code></p><p><code>}</code></p><p>If we created a new variable and typed it as Person, any excess properties in the object will be checked, and Typescript will throw an error.</p><p><code>const x: Person = {</code></p><p><code>&nbsp; &nbsp; firstName: "John",</code></p><p><code>&nbsp; &nbsp; lastName: "Doe",</code></p><p><code>&nbsp; &nbsp; age: 13,</code></p><p><code>}</code></p><p>In this case, you are going to get the following error:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JU0e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JU0e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 424w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 848w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 1272w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JU0e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png" width="915" height="272" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:272,&quot;width&quot;:915,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30986,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JU0e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 424w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 848w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 1272w, https://substackcdn.com/image/fetch/$s_!JU0e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F89577ee2-25bf-4b9d-9307-c78ab759fe58_915x272.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Type '{ firstName: string; lastName: string; age: number; }' is not assignable to type 'Person'. Object literal may only specify known properties, and 'age' does not exist in type 'Person'</figcaption></figure></div><p><br>And this makes sense and is expected because our type <code>Person</code> doesn&#8217;t contain the <code>age</code> property.</p><p>But, there are some situations where Typescript will remain silent when excess properties are available in an object. </p><p>Let&#8217;s explore which situations are those.</p><p>The first situation is when you introduce an object with the excess fields and assign it to a variable typed as <code>Person</code>. </p><p><code>const x = {</code></p><p><code>&nbsp; &nbsp; firstName: "John",</code></p><p><code>&nbsp; &nbsp; lastName: "Doe",</code></p><p><code>&nbsp; &nbsp; age: 13,</code></p><p><code>}</code></p><p><code>const y: Person = x;</code></p><p>In this case, Typescript won&#8217;t check for excess properties as type  <code>Person</code> is a subset of the type inferred for variable <code>x</code>, which is inferred to include all properties in <code>Person</code> plus <code>age</code>. This is known as <strong>duck-typing or structural typing</strong>, which I will look at later.</p><blockquote><p>"If it walks like a duck and it quacks like a duck, then it must be a duck"</p></blockquote><p>And in the second situation, when you use an assertion, this doesn&#8217;t trigger excess property checking in Typescript.</p><p><code>const x = {</code></p><p><code>&nbsp; &nbsp; firstName: "John",</code></p><p><code>&nbsp; &nbsp; lastName: "Doe",</code></p><p><code>&nbsp; &nbsp; age: 13,</code></p><p><code>} as Person;</code></p><h4>Conclusion</h4><p>To recap, excess property checking is only triggered when we define object literals with a type annotation and not in other cases. So, why do we have it? It can be very useful for catching wrong typos and wrong property names. This means it&#8217;s very limited in scope and understanding when Typescript will check for excess properties and when it will not is essential for building a better mental model for understanding and using Typescript.</p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.allthingstypescript.dev/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading All Things Typescript! Subscribe for free to receive new posts and support my work</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>