<?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"><channel><title><![CDATA[Krijan Prajapati]]></title><description><![CDATA[Frontend Engineer]]></description><link>https://krijanprajapati.com.np</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 23:29:59 GMT</lastBuildDate><atom:link href="https://krijanprajapati.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Union in Typescript]]></title><description><![CDATA[Union in typescript allows the variable to hold more than one type of value. It is useful when variable can be of various types. It is defined by |…]]></description><link>https://krijanprajapati.com.np/union-in-typescript</link><guid isPermaLink="true">https://krijanprajapati.com.np/union-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[union type]]></category><dc:creator><![CDATA[Krijan Prajapati]]></dc:creator><pubDate>Sat, 13 Jul 2024 04:22:57 GMT</pubDate><content:encoded><![CDATA[<p>Union in typescript allows the variable to hold more than one type of value. It is useful when variable can be of various types. It is defined by | operator between types.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//Simple Union</span>
<span class="hljs-keyword">let</span> randomValue:<span class="hljs-built_in">string</span>|<span class="hljs-built_in">number</span>=<span class="hljs-number">12</span>;
randomValue=<span class="hljs-string">"John Doe"</span>;
<span class="hljs-comment">//randomValue can either be string or number</span>
</code></pre>
<p>Union Type with Function</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//Union Type with function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomFunc</span>(<span class="hljs-params">params:<span class="hljs-built_in">string</span>|<span class="hljs-built_in">number</span></span>)</span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Print <span class="hljs-subst">${params}</span>`</span>);
}
randomFunc(<span class="hljs-string">"John"</span>);
randomFunc(<span class="hljs-number">12</span>);
<span class="hljs-comment">//Function accepts string or number as its parameter.</span>
</code></pre>
<p>Union Type in Object</p>
<p>In the given example, variable Person can have object with type of Admin or Student.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">type</span> Admin={
name:<span class="hljs-built_in">string</span>;
role:<span class="hljs-built_in">string</span>;
}
<span class="hljs-keyword">type</span> Student={
name:<span class="hljs-built_in">string</span>;
id:id
}
<span class="hljs-keyword">let</span> Person : Admin|Student;
Person={
name:<span class="hljs-string">"Bob"</span>;
role:<span class="hljs-string">"Administrator"</span>
}
Person={
name:<span class="hljs-string">"Leo"</span>,
id:<span class="hljs-number">1</span>
}
</code></pre>
<p>Union Type in Array</p>
<p>The given example demonstrates an array that can contain both string and number values.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> arrayValue:(<span class="hljs-built_in">string</span>|<span class="hljs-built_in">number</span>)[]=[<span class="hljs-string">"John Doe"</span>,<span class="hljs-number">21</span>,<span class="hljs-string">"Jason"</span>,<span class="hljs-number">1</span>,<span class="hljs-number">23</span>];
</code></pre>
<p>Union Type in Literal Values</p>
<p>In the given example variable requestStatus can have literal string value pending, success or error.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> requestStatus:<span class="hljs-string">"pending"</span>|<span class="hljs-string">"success"</span>|<span class="hljs-string">"error"</span>=<span class="hljs-string">"pending"</span>;
requestStatus=<span class="hljs-string">"pending"</span>;
requestStatus=<span class="hljs-string">"error"</span>;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Discussion on Type Annotations and Type Inference]]></title><description><![CDATA[discussion on type annotation and type inference]]></description><link>https://krijanprajapati.com.np/discussion-on-type-annotations-and-type-inference</link><guid isPermaLink="true">https://krijanprajapati.com.np/discussion-on-type-annotations-and-type-inference</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Type Inference]]></category><category><![CDATA[Type Annotation]]></category><dc:creator><![CDATA[Krijan Prajapati]]></dc:creator><pubDate>Fri, 12 Jul 2024 08:38:15 GMT</pubDate><content:encoded><![CDATA[<p><strong>Type Annotations</strong>: Type Annotations is used to define the types of variable, function parameters, return values and object properties.<br />Example:</p>
<pre><code class="lang-typescript"><span class="hljs-comment">// Variables </span>
<span class="hljs-keyword">let</span> value:<span class="hljs-built_in">string</span>=<span class="hljs-string">"Hello My Name is John Doe"</span>;
<span class="hljs-keyword">let</span> secondValue:<span class="hljs-built_in">number</span>=<span class="hljs-number">12</span>;
secondValue=<span class="hljs-number">12</span><span class="hljs-number">-1</span>; <span class="hljs-comment">// No issue </span>
secondValue=<span class="hljs-string">"12"</span> <span class="hljs-comment">// This returns type issue as we have define type number to secondValue</span>
<span class="hljs-keyword">let</span> thirdValue:<span class="hljs-built_in">boolean</span>=<span class="hljs-literal">true</span>
<span class="hljs-comment">//Functions</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">random</span>(<span class="hljs-params">name:<span class="hljs-built_in">string</span></span>):<span class="hljs-title">string</span></span>{
<span class="hljs-keyword">return</span> <span class="hljs-string">`Welcome <span class="hljs-subst">${name}</span>`</span>; 
}
<span class="hljs-comment">//In above function we define function params as type string which returns type string</span>
<span class="hljs-comment">//Objects</span>
<span class="hljs-keyword">const</span> data:{name:<span class="hljs-built_in">string</span>,id:<span class="hljs-built_in">number</span>}={name:<span class="hljs-string">"John Doe"</span>,id:<span class="hljs-number">12</span>}
</code></pre>
<p>Type Inference: Typescript Compiler automatically defines or infers the type of variable based on the value defined to it. This property of typescript is known as type inference.  </p>
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> randomValue=<span class="hljs-string">"John Doe"</span>
<span class="hljs-comment">//In this case TypeScript Compiler automatically assigns the type of randomValue to string.</span>
randomValue=<span class="hljs-string">"Janet"</span>
randomValue=<span class="hljs-number">12</span> <span class="hljs-comment">//shows type error: Error: Type 'number' is not assignable to type 'string'</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Introduction to Typescript]]></title><description><![CDATA[Introduction to typescript pros and cons of typescript]]></description><link>https://krijanprajapati.com.np/introduction-to-typescript</link><guid isPermaLink="true">https://krijanprajapati.com.np/introduction-to-typescript</guid><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Krijan Prajapati]]></dc:creator><pubDate>Thu, 11 Jul 2024 06:07:50 GMT</pubDate><content:encoded><![CDATA[<p>Typescript is basically superset to JavaScript. Typescript allows us to determine types of variables, function parameters, and return values that helps us to catch type-related errors during compile time. Typescript enables developers to catch errors early in the development process through type checking making the life of developers easier during deployment phase. As a whole typescript helps us to make more robust, maintainable, and scalable code, especially in larger projects. Some pros and cons of typescript:</p>
<p>Pros of using Typescript:</p>
<ul>
<li><p><strong>Early Error Detection</strong>: One of the main advantages of using typescript is detection of error early during development ,improving code quality and reducing runtime errors.</p>
</li>
<li><p><strong>Enhanced IDE Support</strong>: IDEs like Visual Studio provides various support like autosuggestion, highlight type issues during coding, refactoring capabilities etc. that makes the code more clean and increase productivity.</p>
</li>
<li><p><strong>Improved Code Quality</strong>: If types are declared properly then code could be more understandable for developers and helpful for future reference. Typescript is more useful in large projects where there are many developers so that their is less confusion in understanding the project.</p>
</li>
<li><p><strong>Advance Type features</strong>: Advance type feature like generics, interfaces, intersection, unions provide more accurate and flexible type definition ensuring flexibility, safety and robustness of the code.</p>
</li>
<li><p><strong>Compatibility with JavaScript</strong>: As a superset of JavaScript, TypeScript allows gradual adoption. Existing JavaScript code can be converted to TypeScript, making the transition smoother.</p>
</li>
</ul>
<p>Cons in using typescript:</p>
<ul>
<li><p><strong>Learning Curve</strong>: Understanding advance type feature can be challenging while starting.</p>
</li>
<li><p><strong>Increase development time</strong>: Writing Type annotations and solving type issues may increase development time of the project</p>
</li>
<li><p><strong>Overhead for small projects</strong>: As typescript increases development time it may not be suitable for smaller projects.</p>
</li>
<li><p><strong>Compilation step :</strong> TypeScript adds an additional compilation step, which can complicate the build process and increase build times. This may affect the development workflow, especially in rapid prototyping scenarios.</p>
</li>
<li><p><strong>Third party libraries :</strong> Third party libraries that have well documentation on JavaScript may not have required documentation or support for TypeScript.  </p>
<p>  Typescript is better for large projects with multiple developers working on same project but for small project that needs to be completed in less time it might not be suitable option especially for the developers just starting with typescript.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Things to learn when you are starting new in Typescript]]></title><description><![CDATA[Lets get started with Typescript]]></description><link>https://krijanprajapati.com.np/thing-to-learn-when-you-are-starting-new-in-typescript</link><guid isPermaLink="true">https://krijanprajapati.com.np/thing-to-learn-when-you-are-starting-new-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Krijan Prajapati]]></dc:creator><pubDate>Tue, 09 Jul 2024 09:42:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720518514854/be2f24d8-f4d9-4693-b230-ac0aa0480096.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is step by step topics that you should learn if you are starting new in typescript:</p>
<ol>
<li><p>Introduction to Typescript</p>
</li>
<li><p>Typescript Annotations</p>
</li>
<li><p>Type Inference</p>
</li>
<li><p>Union Type</p>
</li>
<li><p>Type any</p>
</li>
<li><p>Using Typescript in Arrays</p>
</li>
<li><p>Using Typescript in Objects</p>
</li>
<li><p>Using Typescript in Functions</p>
</li>
<li><p>Optional and Default Parameters</p>
</li>
<li><p>Type Alias</p>
</li>
<li><p>Intersection Types</p>
</li>
<li><p>Type Interface</p>
</li>
<li><p>Interface vs Type Alias</p>
</li>
<li><p>Tuples</p>
</li>
<li><p>Enums</p>
</li>
<li><p>Type unknown, never</p>
</li>
<li><p>Type Guarding</p>
</li>
<li><p>Type Predicates</p>
</li>
<li><p>Generics</p>
</li>
<li><p>Using Typescript while fetching data and use of ZOD library</p>
</li>
<li><p>Typescript Classes</p>
</li>
<li><p>Use Typescript in projects</p>
</li>
</ol>
]]></content:encoded></item></channel></rss>