<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hiruna De Silva on Medium]]></title>
        <description><![CDATA[Stories by Hiruna De Silva on Medium]]></description>
        <link>https://medium.com/@hirunadesilva0422?source=rss-6cd74173a923------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gXwGlbrAAvCf3Zu1ogHfvw.jpeg</url>
            <title>Stories by Hiruna De Silva on Medium</title>
            <link>https://medium.com/@hirunadesilva0422?source=rss-6cd74173a923------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:27:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hirunadesilva0422/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Labeled Boxes: මොනවද මේ TypeScript වල තියෙන Variables සහ Basic Types]]></title>
            <link>https://medium.com/@hirunadesilva0422/labeled-boxes-%E0%B6%B8%E0%B7%9C%E0%B6%B1%E0%B7%80%E0%B6%AF-%E0%B6%B8%E0%B7%9A-typescript-%E0%B7%80%E0%B6%BD-%E0%B6%AD%E0%B7%92%E0%B6%BA%E0%B7%99%E0%B6%B1-variables-%E0%B7%83%E0%B7%84-basic-types-db70e0cbffc5?source=rss-6cd74173a923------2</link>
            <guid isPermaLink="false">https://medium.com/p/db70e0cbffc5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sri-lanka]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Hiruna De Silva]]></dc:creator>
            <pubDate>Sat, 14 Mar 2026 15:11:18 GMT</pubDate>
            <atom:updated>2026-03-14T15:11:18.115Z</atom:updated>
            <content:encoded><![CDATA[<h4>ඔයාගෙ code එක පිළිවෙළට සහ ආරක්ශිතව තියාගන්න, ඔයාගෙ data නිවැරදිව label කරන්නෙ කොහොමද කියල අපි අද බලමු.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rp2stfdUegY8ys_vZtJo5w.png" /></figure><p>හිතන්න, ඔයා ඔයාගෙ PC එකේ තියෙන <strong>films </strong>සහ T<strong>V series </strong>collection එක organise කරනවා කියලා.</p><p>දැන්, ඔයා folders දෙකක් හදනවා. එකක් <strong>“Films” </strong>කියලා, අනිත් එක <strong>“TV Series” </strong>කියලා.</p><p>දැන් ඔයා හරි ඔයාගෙ ළඟම කෙනෙක් හරි ඔයාගෙ PC එකෙන් TV Series එකක් download කරනවා කියල හිතන්නකෝ.</p><p>දැන් ඔයා ඔයාගෙ folders හරියට label කරලා තියෙන නිසා, ඔයා හරි එයා හරි Breaking Bad episode එකක් “Films” folder එකට දාන්න ගියොත් ඒක වැරදි කියලා ඔයාට හෝ එයාට ඒක දාන්න හදනකොටම තේරෙනවා.</p><p>දැන් ඔයාලට තේරෙනවා, ඕනම දේකට label එකක් තියෙනකොට:</p><ul><li><strong>අවුල් අඩු වෙනවා</strong></li><li><strong>වැරදි වැළකෙනවා</strong></li><li><strong>ඇතුළේ තියෙන දේ ආරක්ශා වෙනවා</strong></li></ul><p>Programming වලත් අපි මේ වගේම concept එකක් භාවිතා කරනවා.</p><p>අපි “boxes” භාවිතා කරනවා තොරතුරු ගබඩා කරන්න. ඒ වගේම, ඒ boxes වලට අපි <strong>labels </strong>දෙනවා.</p><p>Programming වල අපි මේ boxes වලට කියනව <strong>Variables </strong>කියල.</p><h3>TypeScript වලින් මොකක්ද කරන්නේ?</h3><p>අපේ කලින් article එකේ අපි ඉගෙන ගත්තා, TypeScript කියන්නේ <strong>static type checker</strong> එකක් කියල.</p><p>ඒ කියන්නේ, ඒක ඔයාගෙ code එක <strong>run වෙන්න කලින්ම</strong> ඔයාගෙ program එකේ type errors තියෙනවද කියලා check කරනවා.</p><p>දැන් අපි බලමු TypeScript data organise කරන්න උදව් කරන <strong><em>Everyday Types </em></strong>කියන concept එක ගැන.</p><h3>Everyday Types කියන්නේ මොනවද?</h3><p>TypeScript වල <em>“Everyday Types”</em> කියන්නේ දෛනික programming tasks වලදි බහුලව භාවිතා කරන basic data types.</p><p>ඒවට අයත් වෙන්නේ:</p><ul><li><strong>string </strong>(text)</li><li><strong>number </strong>(numeric values)</li><li><strong>boolean </strong>(true / false)</li></ul><h3>JavaScript වල තියෙන Label නැති Boxes</h3><p>JavaScript වල variable එකක් කියන්නේ, හරියට නිකන් label එකක් නැති box එකක් වගේ.</p><pre>let gpa = 3.75;  // It holds a number<br>gpa = &quot;First Class&quot;;  // Now it holds text</pre><p>මේ වගේ තැන් වලදි JavaScript complain කරන්නෙ නෑ. Number එකක් text එකකට replace කරලා තිබුණත් ඒක accept කරනවා.</p><p>පස්සෙ වෙලාවක ඔයා gpa variable එක use කරල calculation එකක් කරන්න යනවා.</p><p>හැබැයි ඒ වෙනකොට වෙනකෙනෙක් ඒක string එකකට change කරලා.</p><p>ඔයා gpaඑක number එකක් කියලා හිතාගෙන calculation එකක් කරද්දි…</p><pre>gpa + 0.1;</pre><p>💥 <strong><em>Runtime error</em></strong>.</p><p>මෙන්න මේ වගේ errors prevent කරන්නමයි TypeScript design කරලා තියෙන්නේ.</p><p>TypeScript මේ වැරදි <strong>run වෙන්න කලින්ම</strong> catch කරනවා.</p><h3>TypeScript හි විසඳුම: Boxes Label කිරීම</h3><p>TypeScript ඔයාට <strong>variables label කරන්න අවස්තාව දීල තියෙනවා.</strong></p><p>ඔයාට පුලුවන් variable එක ලිව්වට පස්සෙ colon (:) එකක් දාලා ඔයාගෙ variable එකේ type එක specify කරනවා.</p><pre>let firstName: string = &quot;Hiruna&quot;;</pre><p>දැන් box එක පැහැදිලිව කියනවා:<br>👉 <strong><em>“මේ firstName කියන box එකට දාන්න පුලුවන් text විතරයි.”</em></strong></p><p>ඔයා ඒකට number එකක් දාන්න try කලොත්:</p><pre>firstName = 5;</pre><p>TypeScript එවෙලෙම error එකක් පෙන්නනවා.<br>❌ <strong><em>“මේ box එක string කියලා label කරලා තියෙනවා. ඒක නිසා ඔයාට මේකට numbers දාන්න බෑ”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gijHdTsHrHRYakZFQSK1Cg.png" /></figure><p>දැන් අපේ box එක <strong>ආරක්ශිතයි</strong>.</p><h3>බහුලව භාවිතා කරන Everyday Types 3ක්</h3><p>TypeScript භාවිතා කරන විට අපිට වැඩිපුරම හමුවන මූලික data types තුන පිළිබඳ දැන් බලමු.</p><h4>1️⃣ string (Text සඳහා)</h4><pre>let firstName: string = &quot;John&quot;;</pre><p>👉 ඔයා මේ firstName box එකට පස්සෙ කාලෙක number එකක් assign කරන්න ගියොත්, TypeScript ඔයාව block කරනවා. මොකද, මේක label කරල තියෙන්නෙ string වලට විතරයි.</p><h4>2️⃣ number (Numbers සඳහා)</h4><pre>let age: number = 25;<br>let price: number = 99.99;</pre><p>👉 ඔයා මේ age සහ prices කියන boxes වලට පස්සෙ කාලෙක strings assign කරන්න ගියොත්, TypeScript ඔයාව block කරනවා. මොකද, මේවා label කරල තියෙන්නෙ numbers වලට විතරයි.</p><h4>3️⃣ boolean (True / False සඳහා)</h4><pre>let isStudent: boolean = true;</pre><p>👉 මේ box එකට දාන්න පුලුවන් true/false values විතරයි.</p><h3>TypeScript Compiler එක වැඩ කරන්නෙ කොහොමද?</h3><p>TypeScript code එකක් කෙලින්ම Node.js වල run කරන්න බැහැ.</p><p>මොකද <strong>JavaScript engine වලට</strong>: string වගේ <strong>labels තේරුම් ගැනීමේ හැකියාවක් නෑ.</strong></p><p>ඒක නිසා තමයි අපි <strong>TypeScript compiler (tsc) </strong>එක use කරන්නෙ.</p><p>TypeScript Compiler එක:</p><ol><li>Type labels ටික කියවලා</li><li>Errors check කරලා</li><li>Labels ටික remove කරලා</li><li>Clean JavaScript code එකක් generate කරනවා</li></ol><p><strong>අන්තිමට output එක විදියට ලැබෙන්නෙ pure JavaScript code එකක්.</strong></p><h3>Type Inference: Smart Box එක</h3><p>ඔයා හැම වෙලාවෙම labels manually දාන්න ඕනෙද?</p><p>නෑ, එහෙම ඕන වෙන්නෙ නෑ. TypeScript හරිම smart.</p><p><strong>Type inference</strong> කියන්නේ TypeScript compiler එකට variable එකකට අදාල <strong>type එක ස්වයංක්‍රීයව හඳුනාගැනීමට ඇති හැකියාවට.</strong></p><p>මේ feature එක නිසා අතිරේක boilerplate code ලියන අවශ්‍යතාව අඩුවෙනව වගේම type safety එකත් රැකගන්න පුළුවන්.</p><pre>let country = &quot;Sri Lanka&quot;;</pre><p>මෙතනදි : string කියලා label කරල නැති වුණත්, TypeScript automatically තේරුම් ගන්නවා &quot;Sri Lanka&quot; කියන්නෙ text එකක් කියල</p><p>ඔයා පසුකාලීනව country කියන box එක ඇතුලට number එකක් දාන්න try කලොත්:</p><pre>country = 123;</pre><p>TypeScript still ඔයාව block කරනවා.</p><p>ඒ කියන්නෙ, ඔයා label එකක් ලිව්වෙ නැති උනත් එතන label එකක් තියෙනවා.</p><h3>සාරාංශය</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leMYYNNYAHYuGtbxh75ToA.png" /></figure><p>අපි දැන් ඉගෙනගත්ත දේවල් සරලව තේරුම්ගමු.</p><ul><li>Variables කියන්නේ data hold කරන boxes වලට.</li><li>JavaScript boxes වලට label නෑ.</li><li>TypeScript boxes වල label තියෙනවා.</li><li>TypeScript runtime errors prevent කරනවා.</li><li>TypeScript code compile කරන්න ඕනෙ, මොකද JavaScript engines වලට labels අඳුරගන්න හැකියාවක් නෑ.</li></ul><p>දැන් අපි simple data store කරන හැටි ඉගෙන ගත්තා.</p><p>හැබැයි, මොකද වෙන්නෙ අපිට store කරන්න ඕනෙ නම්:</p><ul><li>List එකක්?</li><li>Shopping cart එකක්?</li><li>Complex registration form එකක්?</li></ul><p>ඊළඟ article එකේ අපි <strong>Arrays සහ Objects</strong> ගැන ඉගෙන ගමු.</p><p>මේ article එක ඔබට ප්‍රයෝජනවත් වුණා නම්, මේ TypeScript series එක follow කරන්න.<br><strong> </strong>ප්‍රශ්න හෝ අදහස් තියෙනවා නම් comment එකක් දාන්නත් අමතක කරන්න එපා.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db70e0cbffc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Labelled Boxes: Understanding Variables and Basic Types in TypeScript]]></title>
            <link>https://medium.com/@hirunadesilva0422/labelled-boxes-understanding-variables-and-basic-types-in-typescript-fbe433be8b80?source=rss-6cd74173a923------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbe433be8b80</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Hiruna De Silva]]></dc:creator>
            <pubDate>Sat, 14 Mar 2026 15:08:40 GMT</pubDate>
            <atom:updated>2026-03-14T15:08:40.973Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Keep your code tidy and safe by learning how to label your data properly.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rp2stfdUegY8ys_vZtJo5w.png" /></figure><p>Imagine you are organising your university documents.</p><p>You create a file folder and name it <strong><em>&quot;Semester 2&quot;.</em></strong></p><p>Because of that label, everyone knows that putting your <strong><em>Semester 1 maths assignment</em></strong> inside that folder would be a mistake.</p><p>Labels,</p><ul><li><strong>Prevent confusion.</strong></li><li><strong>Prevent mistakes.</strong></li><li><strong>Protect what’s inside.</strong></li></ul><p>In programming, we also use <em>“boxes” </em>to store information.</p><p>We call them <strong>variables</strong>.</p><h3>A Quick Reminder: <strong>What </strong>TypeScript Does</h3><p>In our previous article, we learned that <strong>TypeScript acts as a static type checker</strong>.</p><p>That means it checks your code <strong>before it runs</strong>, making sure your program follows the rules and doesn’t contain type errors.</p><p>Today, we’ll see how TypeScript helps us safely organise our data using something called <strong><em>Everyday Types</em></strong>.</p><h3>What Are Everyday Types?</h3><p>In TypeScript, “E<strong><em>veryday Types</em></strong>&quot; refer to the fundamental, frequently used data types required for daily programming tasks.</p><p>These include primitives like <strong>string </strong>(text), <strong>number </strong>(numeric values), and <strong>boolean </strong>(true/false), as well as composite types like <strong><em>array </em></strong>and <strong><em>object </em></strong>types.</p><h3>The Unlabeled Boxes of JavaScript</h3><p>In standard JavaScript, a variable is like a box with no label.</p><pre>let gpa = 3.75;   // It holds a number<br>gpa = &quot;First Class&quot;; // Now it holds text</pre><p>JavaScript doesn’t complain. It happily allows you to replace a number with text.</p><p>Later in your program, you might try to perform a calculation using gpa, assuming it is still a number.</p><p>But someone changed it to a string.</p><pre>gpa + 0.1;</pre><p>💥<em> </em><strong><em>Runtime error.</em></strong></p><p>This is exactly the kind of problem TypeScript was designed to prevent.</p><p>TypeScript catches these errors <strong>before your code even runs</strong>.</p><h3>The TypeScript Solution: Labeling Your Boxes</h3><p>TypeScript introduces <strong>strongly typed variable declarations.</strong></p><p>You can add a label to your box using a colon (:) followed by the type name.</p><pre>let firstName: string = &quot;Hiruna&quot;;</pre><p>Now the box clearly says:<br>👉 <strong><em>“This box can only hold text.”</em></strong></p><p>If you try:</p><pre>firstName = 5;</pre><p>TypeScript immediately throws an error.<br>❌ <strong><em>“Error! This box is labelled ‘string’. You can’t put a number inside it.”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gijHdTsHrHRYakZFQSK1Cg.png" /></figure><p>The box is <strong>protected</strong>.</p><h3>The Three Everyday Types You’ll Use Most</h3><p>Let’s look at the three most common basic types in TypeScript.</p><h4>1️⃣ string (Represents textual data)</h4><p>Use string when your variable should hold text.</p><pre>let firstName: string = &quot;John&quot;;</pre><p>If you try assigning a number later, TypeScript will stop you.</p><p>✅ Simple, Safe and Predictable.</p><h4>2️⃣ number (Represents numeric values)</h4><p>Unlike some languages that separate integers and decimals, TypeScript uses number for all numeric values.</p><pre>let age: number = 25;<br>let price: number = 99.99;</pre><p>👉 Whether it’s 10 or 10.75, it’s still a number.</p><h4>3️⃣ boolean (Represents the two logical values)</h4><p>A boolean can only be true or false.</p><p>Think of it like a light switch.</p><pre>let isStudent: boolean = true;</pre><p>❌ It can’t be &quot;maybe&quot;.<br>❌ It can’t be 1.<br>❌ It can’t be &quot;yes&quot;.</p><p>✅ Only true or false.</p><h3>What Happens Behind the Scenes?</h3><p>If you try running this TypeScript code directly using standard Node.js, <em>it will fail</em>.</p><p>Because<em> </em><strong>JavaScript engines do not understand labels</strong> like : string.</p><p>Those labels are <strong>TypeScript-only features</strong>.</p><p>That’s why we use the <strong>TypeScript compiler (</strong><strong>tsc)</strong>.</p><p>The compiler:</p><ol><li>Reads your type labels</li><li>Checks for mistakes</li><li>Removes the labels</li><li>Converts everything into clean JavaScript</li></ol><p>The <strong>final output is pure JavaScript</strong> that your computer can execute safely.</p><h3>Type Inference: The Smart Box</h3><p>Do you always have to manually write the label?</p><p>Not necessarily. TypeScript is smart.</p><p>It has something called <strong>Type Inference</strong>.</p><p>Type inference is the ability of the TypeScript compiler to <strong>automatically determine the type</strong> of variables.</p><p>This feature reduces the need for boilerplate code and maintains type safety.</p><pre>let country = &quot;Sri Lanka&quot;;</pre><p>Even though we didn’t write : string, TypeScript looks at &quot;Sri Lanka&quot; and automatically understands:</p><p><strong><em>“This is text. I will treat this variable as a string.”</em></strong></p><p>If you later try:</p><pre>country = 123;</pre><p>TypeScript will still block you.</p><p>The label exists, even if you didn’t explicitly write it.</p><h3>Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leMYYNNYAHYuGtbxh75ToA.png" /></figure><p>Let’s simplify everything:</p><ul><li>Variables are boxes that hold data.</li><li>JavaScript boxes have no labels.</li><li>TypeScript lets you label your boxes.</li><li>TypeScript prevents runtime type errors by checking mistakes before execution.</li><li>You must compile TypeScript because JavaScript engines cannot understand type labels directly.</li></ul><p>Now that we know how to store simple pieces of data, what happens when we want to store:</p><ul><li>A whole list of toys?</li><li>A shopping cart?</li><li>A complex registration form?</li></ul><p>In the next article, we’ll level up and explore <strong>Arrays </strong>and <strong>Objects </strong>in TypeScript.</p><p>If you found this helpful, follow me for the next part of this TypeScript series, and feel free to highlight or comment with questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbe433be8b80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript vs JavaScript: Code ලියන්න “Safety Net” එකක් අවශ්‍ය ඇයි? ️]]></title>
            <link>https://medium.com/@hirunadesilva0422/typescript-vs-javascript-code-%E0%B6%BD%E0%B7%92%E0%B6%BA%E0%B6%B1%E0%B7%8A%E0%B6%B1-safety-net-%E0%B6%91%E0%B6%9A%E0%B6%9A%E0%B7%8A-%E0%B6%85%E0%B7%80%E0%B7%81%E0%B7%8A-%E0%B6%BA-%E0%B6%87%E0%B6%BA%E0%B7%92-%EF%B8%8F-52584c77411f?source=rss-6cd74173a923------2</link>
            <guid isPermaLink="false">https://medium.com/p/52584c77411f</guid>
            <category><![CDATA[static-vs-dynamic-typing]]></category>
            <category><![CDATA[sri-lanka]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hiruna De Silva]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 08:23:55 GMT</pubDate>
            <atom:updated>2026-02-08T08:23:55.850Z</atom:updated>
            <content:encoded><![CDATA[<p>ඔයාගෙ code එක සැරින් සැරේ break වෙන එක නවත්තන ආරක්ශකයා, <strong>TypeScript </strong>කියන්නෙ මොකක්ද කියල අද අපි කතා කරමු.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFuJ3oZMhCitHT7CYlbAFg.png" /></figure><p>හිතන්න, ඔයා ඔයාගෙ phone එකේ contact එකක් save කරනවා කියලා.</p><p>ඔන්න ඔයා ඔයාගෙ “<strong>අම්මා</strong>” ගෙ number එක save කරන්න යන්නේ. හදිස්සියට ඔයා number එක save කරනකොට, phone number එක වෙනුවට “abcxyz” කියලා random text එකක් තමයි type කරලා තියෙන්නේ.</p><p>ඔයාගෙ phone එක මේ වෙලාවෙ <strong>JavaScript </strong>පාවිච්චි කර කර ඉදියනම්, එයා කියනවා,</p><p>“<strong><em>හරි, මං අම්මාගෙ number එක save කරගත්තා.</em></strong>” කියලා.</p><p>එහෙම කිව්වට පස්සෙ ඔයත් කිසි අව්ලක් නැතුව වැඩ ටික කරන් ඉන්නවා. හැබැයි, ප්‍රශ්නෙ වෙන්නෙ ඔයා හදිස්සියක් වෙලා අම්මාට call කරන්න හදනකොට. <strong>දැන් phone එකේ save වෙලා තියෙන්නේ ඔයාගෙ අම්මාගෙ number එක වෙනුවට random text එකක්.</strong></p><p>දැන් හිතන්න ඔයා අම්මගෙ number එක වෙනුවට වැරදීමකින් “abcxyz” save කරන මොහොතෙ ඔයාගෙ phone එක පාවිච්චි කරන්නේ <strong>TypeScript </strong>කියලා. එහෙනම් ඔයා “abcxyz”, phone number එකක් විදියට save කරන්න ගිය <strong>මොහොතේම </strong>system එක කියනවා:</p><p>“<strong><em>❌ ඔයා ඔය type කරපු එකේ වැරැද්දක් තියනවා. Phone number එකක තියෙන්න පුලුවන් digits විතරයි. පොඩ්ඩක් ආපහු බලන්න.</em></strong>” කියලා.</p><p>එතකොට ඔයාට පුලුවන් ඔයා mistake එක <strong>කරන්න කලින්ම</strong> ඒක fix කරන්න.</p><p>👉 <strong>මේක තමයි JavaScript සහ TypeScript අතර ඇති ප්‍රධාන වෙනස.</strong></p><p><strong>JavaScript</strong>, mistakes වලට ඉඩ දීලා පස්සේ <strong>runtime එකේදි තමයි fail කරන්නේ</strong>. හැබැයි <strong>TypeScript</strong>, mistakes code එක ලියන වෙලාවේම අදුරගෙන එවෙලෙම fail කරනවා. හරියට නිකං <strong>safety net 🛡️</strong> එකක් වගේ.</p><p>මේ series එක තුළ, අපි <strong>TypeScript මුල සිට</strong> ඉගෙනගන්නවා.<br>නමුත් code ලියන්න කලින්, මේ ප්‍රශ්නයට උත්තරයක් හොයමු,<br>👉 <strong>අපිට TypeScript ඇත්තටම අවශ්‍යද?</strong></p><h3><strong>JavaScript වල ඇති ගැටළුව</strong></h3><p><strong>JavaScript </strong>තමයි websites සහ web applications build කරන්න පාවිච්චි කරන වඩාත් <strong>ජනප්‍රියම language</strong> එක වෙන්නේ.</p><p>හැබැයි JavaScript වල ගැටළු කිහිපයක් තියෙනවා.</p><p>JavaScript මුලින්ම හදලා තියෙන්නේ <strong>කුඩා ප්‍රමාණයේ applications සදහා පමණයි</strong>. විශාල applications සදහා නෙවෙයි.</p><p>නමුත් අද අපි එය විශාල ප්‍රමාණයේ:</p><ul><li>Front-end applications</li><li>Back-end servers</li><li>Enterprise-level systems</li></ul><p>සදහා භාවිත කරනවා.</p><p>JavaScript කියන්නේ <strong>dynamically typed language </strong>එකක්.<br>ඒ කියන්නේ:<br>👉 Operations වල types, code එක run වෙනකන් check කරන්නේ නෑ. Runtime එකේ දි තමයි check කරන්නේ.</p><h4>Example 1 (JavaScript): Wrong type, no warning</h4><pre>let age = &quot;20&quot;;<br>console.log(age + 1);</pre><p>✅ Code එක කිසිම error එකක් නැතුව run වෙනවා.</p><p>❌ හැබැයි, output එක විදියට ලැබෙන්නේ 201. නැතුව, 20ට 1ක් එකතු කරා ම උත්තරය විදියට ලැබෙන 21 නෙවෙයි.</p><p>මෙතන JavaScript <strong>කිසිම error එකක් පෙන්නන්නේ නැහැ</strong>. හැබැයි, මේක bug එකක්.</p><h4><strong>Example 2 (JavaScript): </strong>Accessing data that doesn’t exist</h4><pre>let user = {};<br>console.log(user.name.toUpperCase());</pre><p>❌ මේ code එක <strong>ලියන වෙලාවෙ දි කිසිම අවුලක් පෙන්නන්නේ නෑ</strong>. හැබැයි, <strong>run කරන වෙලාවෙ දි crash වෙනවා</strong>.</p><p>මොකද මෙතන <strong>user කියන්නේ empty object</strong> එකක්. ඒක නිසා user ට name එකක් <strong>define </strong>වෙලා නෑ.</p><p>මේ වගේ problems වලට අපි කියනවා <strong>type errors</strong> කියල.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcVmay1I6t2Dz2Psh1d0SA.png" /></figure><h3><strong>TypeScript: අපේ “Safety Net” එක 🛡️</strong></h3><p>TypeScript කියන්නේ <strong>static type checker</strong> එකක් තියෙන <strong>statically typed language</strong> එකක්.</p><p>ඒක අහද්දි ටිකක් සංකීර්ණයි වගේ නේද?</p><p>නමුත් ඒක අදහස ඉතාම සරලයි.</p><ul><li><strong>Statically typed</strong> → Types check වෙන්නේ code එක develop කරන වෙලාවෙමයි. ඒ කියන්නේ code එක run කරන්න කලින්</li><li><strong>Static</strong> → Code එක ලියන වෙලාවෙදි ම ඔයාට errors බලාගන්න පුලුවන්. Code එක run වෙනකන් ඉන්න ඕන නෑ</li><li><strong>Type checker</strong> → ඔයාගෙ data එකේ label එක සහ actual value එක match වෙනවද කියලා බලනවා</li></ul><p>TypeScript කියන්නේ හරියට නිකං JavaScript වටා තියෙන <strong>ආරක්ශිත ආවරණයක්</strong> වගේ.</p><p>👉 TypeScript, JavaScript වලට කරන්න පුලුවන් දේවල් වෙනස් කරන්නෙ නෑ. ඒක <strong>mistakes වේලාසනින් වලක්වනවා විතරයි</strong>.</p><h4>The Same Example 1 (TypeScript): Wrong Type Caught Early</h4><pre>let age: number = &quot;20&quot;;</pre><p>❌ TypeScript ඉක්මනින් error එක පෙන්නනවා.<br><strong><em>Type ‘string’ is not assignable to type ‘number’</em></strong></p><p>දැන්, Bug එක code එක run කරන්න කලින්ම අදුරගන්න පුලුවන් ✅</p><p><strong>Same Example 2 (TypeScript): Safer Objects</strong></p><pre>type User = {<br>  name: string;<br>};<br><br>let user: User = {};</pre><p>❌ Error:<br><strong><em>Property ‘name’ is missing</em></strong></p><p>TypeScript, production එකට යන්න කලින්, <strong>development time එකේම problem එක fix කරන්න අවස්ථාව ලබාදෙනවා</strong>👍</p><h3><strong>TypeScript ඇත්තටම වැඩ කරන්නේ කොහොමද?</strong></h3><p>Chrome, Firefox වගේ <strong>browsers වලට ඇත්තටම TypeScript තේරෙන්නෙ නෑ</strong>. එයාලට තේරෙන්නෙ JavaScript විතරයි.</p><p>TypeScript කරන්නේ <strong>translator </strong>කෙනෙක් වගේ වැඩ කරන එක.</p><ol><li>Programmer, TypeScript වලින් code එක ලියනවා</li><li>Compiler එක run කරනවා</li><li>Compiler එක errors තියෙනවද කියල check කරනවා</li><li>Errors නැත්තම්, compiler එක මගින් TypeScript code එක JavaScript වලට compile කරනවා</li><li>දැන් Browser එක තමන්ට තේරෙන භාෂාවෙන් තියෙන JavaScript code එක run කරනවා</li></ol><p>📌 <strong>වැදගත්:</strong></p><p>TypeScript browser එකට යන්නේ නැහැ. <strong>Compile වෙලා disappear වෙනවා</strong>.</p><h3><strong>TypeScript </strong>වලට <strong>බය වෙන්න එපා</strong></h3><p>ගොඩක් beginners ලා හිතනවා:</p><p><strong><em>“TypeScript හරි අමාරුයි”<br>“Extra work වැඩියි”</em></strong></p><p>මේක <em>බොරු බයවීමක්</em> 😄</p><p>ඔව්, මුලදි ටිකක් අමාරුයි වගේ තේරෙවි.</p><p>හැබැයි, පුරුදු වෙනකන් අමාරුවෙන් හරි TypeScript පාවිච්චි කරොත් ඔයාට <strong>වටිනා ප්‍රතිලාභ ගොඩක් හම්බවෙනවා</strong>.</p><ul><li>Runtime bugs අඩු වෙනවා</li><li>Editor autocomplete හොඳයි</li><li>Team work easy වෙනවා</li><li>Code එක self-documenting වෙනවා</li></ul><p>ඒ වගේම, වෙන developer කෙනෙක් හරි ඔයාගෙ senior කෙනෙක් හරි ඔයාගෙ code එක බලද්දි:</p><ul><li>මොන data ද expect කරන්නෙ</li><li>මොන functions ද return වෙන්නේ</li><li>මොනවද allow කරන්නෙ සහ මොනවද නොකරන්නෙ</li></ul><p>මේ හැමදේම TypeScript එයාට clearly කියල දෙනව 👍</p><h3>සාරංශය</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzvOZhEL181gPUX8a3_wMw.png" /></figure><ul><li>JavaScript <strong>compile-time එකේදි mistakes වලට අවසර දීල runtime එකේදි ඒවා fail කරනව</strong></li><li>TypeScript, <strong>code run කරන්න කලින් compile-time එකේදි ම mistakes catch කරනවා</strong></li><li>TypeScript මගින් JavaScript replace කරන්නේ නැහැ. TypeScript කියන්නේ <strong>JavaScript වල superset එකක්</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52584c77411f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript vs JavaScript: Why You Need a Safety Net ️]]></title>
            <link>https://medium.com/@hirunadesilva0422/typescript-vs-javascript-why-you-need-a-safety-net-%EF%B8%8F-8e5dec83a6dd?source=rss-6cd74173a923------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e5dec83a6dd</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[static-vs-dynamic-typing]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hiruna De Silva]]></dc:creator>
            <pubDate>Mon, 02 Feb 2026 17:26:23 GMT</pubDate>
            <atom:updated>2026-02-02T17:26:23.912Z</atom:updated>
            <content:encoded><![CDATA[<p>Stop breaking your code and learn why more developers are now choosing TypeScript over plain JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFuJ3oZMhCitHT7CYlbAFg.png" /></figure><p>Imagine you are saving a contact on your phone.</p><p>You create a contact named <strong>“Mom”</strong>, but because you are in a hurry, you accidentally type a random string like <strong>“abcxyz”</strong> instead of a phone number.</p><ul><li>If you are using <strong>JavaScript</strong>, the phone says:<br><strong><em>“Okay, saved.”</em></strong><em><br></em>Everything looks fine until you actually try to call <strong>Mom</strong> 📵.</li><li>Now imagine using <strong>TypeScript</strong>. The moment you try to save <strong>“abcxyz”</strong> as a phone number, the system stops you and says:<br>“<em>❌ </em><strong><em>Error! A phone number must contain only digits.”<br></em></strong>You fix the mistake <strong>before</strong> saving the contact.</li></ul><p>That’s the core difference between <strong>JavaScript</strong> and <strong>TypeScript</strong>.</p><p>JavaScript lets mistakes slip through and fail <strong>later at runtime</strong>. <br>But TypeScript catches those mistakes <strong>early, while you are writing the code, acting as a safety net</strong> 🛡️.</p><p>In this series, we are going to learn TypeScript <strong>from scratch</strong>. <br>But before we write any code, we need to answer one important question:<br><strong><em>Why do we need TypeScript at all?</em></strong></p><h3><strong>The Problem with JavaScript</strong></h3><p>JavaScript is the <strong>most popular language</strong> on the web. But there’s a problem.</p><p>JavaScript was originally created for <strong>small scripts</strong>, not massive applications.</p><p>But today, we use it for:</p><ul><li>Large front-end apps</li><li>Back-end servers</li><li>Enterprise-level systems</li></ul><p>JavaScript is a very <strong>loose </strong>and <strong>dynamically typed</strong> language. That means it <strong>allows </strong>many operations without checking types until runtime.</p><h4><strong>Example 1 </strong>(JavaScript)<strong>: Wrong type, no warning</strong></h4><pre>let age = &quot;20&quot;;<br>console.log(age + 1);</pre><p>✅ This code <strong>runs.</strong></p><p>❌ But the output is 201, not 21.</p><p>JavaScript <strong>doesn’t complain</strong> even though this is probably a bug.</p><h4>Example 2 (JavaScript): Accessing data that doesn’t exist</h4><pre>let user = {};<br>console.log(user.name.toUpperCase());</pre><p>❌ This crashes <strong>at runtime</strong>, not while writing code.</p><p>These problems are called <strong>type errors:</strong> using a value in a way it was never meant to be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcVmay1I6t2Dz2Psh1d0SA.png" /></figure><h3><strong>Enter TypeScript: The “Safety Net”</strong></h3><p>TypeScript is a <strong>statically typed language</strong> with a <strong>static type checker.</strong></p><p>That sounds complex, but it’s actually simple.</p><ul><li>Statically typed: Types are checked at development time, before the code runs.</li><li><strong>Static: </strong>Errors are detected while you are writing the code, not at runtime.</li><li><strong>Typechecker: </strong>It ensures the “labels” on your data match what’s actually inside.</li></ul><p>Think of TypeScript as a <strong>protective wrapper</strong> around JavaScript.<br>It doesn’t change what JavaScript can do; it just <strong>prevents mistakes early</strong>.</p><h4>The Same Example 1 (TypeScript): Wrong Type Caught Early</h4><pre>let age: number = &quot;20&quot;;</pre><p>❌ TypeScript immediately shows an error:<br><strong><em>Type ‘string’ is not assignable to type ‘number’</em></strong></p><p>Now the bug is caught <strong>before the code ever runs</strong>.</p><h4>The Same Example 2 (TypeScript): Safer Objects</h4><pre>type User = {<br>  name: string;<br>};<br><br>let user: User = {};</pre><p>❌ Error:<br><strong><em>Property ‘name’ is missing</em></strong></p><p>TypeScript forces you to fix problems <strong>at development time</strong>, not in production.</p><h3>How Does TypeScript Actually Work?</h3><p>Computers and browsers (like Chrome or Firefox) actually <strong>cannot</strong> understand TypeScript. They <strong>only understand JavaScript.</strong></p><p>So, TypeScript acts like a <strong>translator</strong>.</p><p>1. You write code in TypeScript (with all the safety rules).</p><p>2. You run a tool called a <strong>Compiler</strong>.</p><p>3. The compiler checks for errors.</p><p>4. If there are no errors, the compiler “translates” (compiles) your code into clean JavaScript.</p><p>5. Your browser runs the clean JavaScript.</p><h3>Why You Should Not Be Afraid of TypeScript</h3><p>Many beginners have a “<strong>false fear</strong>” that TypeScript is hard or too much extra work.</p><p>Yes, you write a little more code at first. But in return, you get:</p><ul><li>Fewer runtime bugs</li><li>Better editor autocomplete</li><li>Easier teamwork</li><li>Self-documenting code</li></ul><p>Also, when someone else reads your code, TypeScript clearly tells them:</p><ul><li>What data is expected</li><li>What functions return</li><li>What is allowed and what is not</li></ul><h3><strong>Summary</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzvOZhEL181gPUX8a3_wMw.png" /></figure><ul><li>JavaScript allows many mistakes and fails <strong>at runtime.</strong></li><li>TypeScript catches mistakes <strong>before your code runs.</strong></li><li>TypeScript is <strong>not a replacement; i</strong>t is a <strong>superset of JavaScript</strong></li></ul><p>If you found this helpful, follow me for the next part of this TypeScript series, and feel free to highlight or comment with questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e5dec83a6dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Test Automation: A Guide to Selenium WebDriver and Mocha]]></title>
            <link>https://medium.com/@hirunadesilva0422/mastering-test-automation-a-guide-to-selenium-webdriver-and-mocha-8f5724c23b77?source=rss-6cd74173a923------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f5724c23b77</guid>
            <dc:creator><![CDATA[Hiruna De Silva]]></dc:creator>
            <pubDate>Wed, 05 Jun 2024 06:31:21 GMT</pubDate>
            <atom:updated>2024-06-05T06:31:21.509Z</atom:updated>
            <content:encoded><![CDATA[<p>Automation testing is an essential part of modern software development. It saves time, improves accuracy, and allows developers to focus on creating new features. In this guide, we’ll explore how to use <strong><em>Selenium WebDriver</em></strong> and <strong><em>Mocha</em></strong> to create and run automated tests for your <strong>JavaScript</strong> web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*844sHbaMWuCTxzA1" /><figcaption>Photo by <a href="https://unsplash.com/@cdr6934?utm_source=medium&amp;utm_medium=referral">Chris Ried</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>While this tutorial focuses on JavaScript, Selenium WebDriver is a versatile tool that supports multiple programming languages such as <strong>Python, Java, C#, and Ruby</strong>. You can use similar approaches and integrate with other testing tools specific to these languages to automate your tests.</p><h3>Prerequisites</h3><p>Before diving into this tutorial, you should have a basic understanding of the following:</p><ul><li><strong>Fundamentals of JavaScript:</strong> Familiarity with JavaScript syntax and concepts.</li><li><strong>Testing Applications:</strong> Basic knowledge of how testing works in the context of software development.</li><li><strong>Node.js and npm:</strong> Ensure Node.js and npm are installed on your machine. You can download them from the <a href="https://nodejs.org/"><strong>official Node.js website</strong></a><strong>.</strong></li></ul><h3>Setting Up the Environment</h3><p>To begin, you need to set up your development environment. If you don’t already have a JavaScript project, follow these steps to create one:</p><h4>Installing Node.js and npm</h4><p>Ensure you have Node.js and npm installed on your machine. You can download them from the <a href="https://nodejs.org/">official Node.js website</a>. After installation, verify the installations by running the following commands in your terminal:</p><pre>node -v<br>npm -v</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q5q8vxUqTeb-hgj_" /><figcaption>Photo by <a href="https://unsplash.com/@lautaroandreani?utm_source=medium&amp;utm_medium=referral">Lautaro Andreani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Setting Up a New Project</h4><p>If you do not already have a JavaScript project, create one by following these steps:</p><ol><li>Create a new project.</li><li>Navigate into the directory.</li></ol><pre>npx create-react-app test-automation<br>cd test-automation</pre><h3>Installing Selenium WebDriver and Mocha</h3><p>To create and run automated test scripts, you’ll need to install a couple of tools.</p><ul><li><strong>Selenium WebDriver:</strong> This is required to read and interact with the web elements in your test scripts.</li><li><strong>Mocha:</strong> This is needed to run the test scripts.</li></ul><p>Run the following commands to install these dependencies:</p><pre>npm install selenium-webdriver<br>npm install mocha</pre><h3>Adding Selenium IDE Extension</h3><p>After installing the necessary dependencies, you need to add the Selenium IDE extension to your web browser. Selenium IDE is a powerful tool that allows you to generate test scripts by recording your interactions with the web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g1-6PmJJ8DPBer6N" /><figcaption>Photo by <a href="https://unsplash.com/@zanlazarevic?utm_source=medium&amp;utm_medium=referral">Zan Lazarevic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Once the extension is added, you can use it to record and generate test scripts for your web application.</p><h3>Creating and Recording a Test Script with Selenium IDE</h3><p>After adding the Selenium IDE extension, follow these steps to create and record a test script:</p><ol><li><strong>Create a New Project:</strong></li></ol><ul><li>Click on the Selenium IDE extension icon in your browser.</li><li>Create a new project by clicking “Create a new project”.</li></ul><p><strong>2. Run Your Project:</strong></p><ul><li>Run your web application on a server or localhost.</li><li>Copy the URL of your project.</li></ul><p><strong>3. Set Up Selenium IDE:</strong></p><ul><li>Paste the copied URL in Selenium IDE.</li></ul><p><strong>4. Start Recording:</strong></p><ul><li>Add a new test by clicking the “+” button.</li><li>Start recording your test script by clicking the “Record” button.</li><li>A new window will prompt, displaying your project.</li></ul><p><strong>5. Perform Actions:</strong></p><ul><li>Interact with the new window and perform the actions you want to test.</li><li>Once you have completed the actions, stop the recording by clicking the “Stop” button.</li></ul><p><strong>6. Review and Export the Test:</strong></p><ul><li>You will see your recorded test steps in Selenium IDE.</li><li>To export the test, click on the three dots next to the test name and select “Export”.</li><li>Choose “JavaScript Mocha” (or the relevant language) as the export format.</li></ul><h3>Integrating the Test Script into Your Project</h3><p>After exporting your test script, you need to integrate it into your project:</p><ol><li><strong>Create a Test Folder:</strong></li></ol><ul><li>In the root folder of your project, create a new folder named test.</li></ul><p><strong>2. Create a Test File:</strong></p><ul><li>Inside the test folder, create a new file with a .test.js or .spec.js extension (e.g., sample.test.js).</li></ul><p><strong>3. Copy the Test Script:</strong></p><ul><li>Open the exported test script from Selenium IDE.</li><li>Copy the content of the test script and paste it into your newly created test file.</li></ul><p>By following these steps, you will have your automated test script ready to be executed with Mocha and Selenium WebDriver.</p><h3>Updating package.json</h3><p>To run your tests using Mocha, you need to update the scripts section of your package.json file to include the following test command:</p><pre>&quot;scripts&quot;: {<br>  &quot;test&quot;: &quot;mocha test&quot;<br>}</pre><h3>Running Your Tests</h3><p>Finally, run your tests by executing the following command in your terminal:</p><pre>npm test</pre><h3>Conclusion</h3><p>In this guide, we covered the essential steps to set up an automated testing environment using Selenium WebDriver and Mocha. We walked through installing the necessary tools, adding the Selenium IDE extension to your browser, creating and recording test scripts, integrating these scripts into your project, and finally running the tests.</p><p>Automation testing is a powerful way to ensure the reliability and quality of your web applications, saving you time and effort in the long run. By following these steps, you can streamline your testing process and focus more on developing new features. Happy testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f5724c23b77" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>