<?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[Rajiv]]></title><description><![CDATA[Frontend Developer]]></description><link>https://script.thoughtlessmind.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 22 May 2026 17:05:43 GMT</lastBuildDate><atom:link href="https://script.thoughtlessmind.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding  Function Overload in TypeScript]]></title><description><![CDATA[What are Function Overloads?
Function Overloads in Typescript allow us to define multiple function signatures for the same function. Each signature specifies a particular set of parameter types and the corresponding return type. This feature enables ...]]></description><link>https://script.thoughtlessmind.dev/function-overload-in-typescript</link><guid isPermaLink="true">https://script.thoughtlessmind.dev/function-overload-in-typescript</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Rajiv Kumar]]></dc:creator><pubDate>Wed, 09 Aug 2023 17:33:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1691227799345/8a2ba547-9686-4817-8ad0-a28ec683cb87.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-are-function-overloads"><strong>What are Function Overloads?</strong></h3>
<p>Function Overloads in Typescript allow us to define multiple function signatures for the same function. Each signature specifies a particular set of parameter types and the corresponding return type. This feature enables TypeScript to perform accurate type checking and inference, ensuring the function behaves correctly with different argument combinations.</p>
<p><em>TLDR, Show me the code</em>: <a target="_blank" href="https://www.typescriptlang.org/play?ssl=22&amp;ssc=1&amp;pln=12&amp;pc=1#code/PTAEDEFcDsGMBcCWB7aoDOiDm0CG9IAnAU1ADNlDRcATGxaLUaSAWwCNjD1robQSBQtAZNczNp0IAoMjAQo0tGgApcALgkcuAGlDtNLbYQCUhyVwDc06SAjykqDNjxDSFKrFSx8xV6Ix4QlEeXD4BYiERRmpA4MZZB0VqOjVNdCDRPQM40TNcxmtbMCg4RzREVgAHABtiVj94fGT4AAt8UHa+Op52ZDbQH3RidESy5OU03gBPbM0w6fyF0ABvaVAIqNiAan1rAF8bOwB1RBqazaI0DPimRDJB1AA3LngAFWQAZUyYxB4gyDEMYKJxeaAvQjvZAAVRE8BUT1wNUB5mMejBEKh31umgBxHyN1ERTsAHczhdBFctFJQPdHuDXh9sQE-uQkcNgeV6ZiPrDEPDEcjiKipPkjFIinJxqDnoyYXCEUiUdTdI8eV8flgAPyaPrIOphEyrda0h4qLzq5mMI2U4SgQWAgB08A1txUJmsG1taAdxAONjBGW5r2INCtWAAakrSABeYOQ3kKgCMAAY9HiPcUNtmAHpagOoIMYkM0ABybCjQtAceLCfl-JUqczdmzoDzNmkQA">TS Playground for example</a></p>
<h3 id="heading-how-to-use-function-overloads"><strong>How to Use Function Overloads</strong></h3>
<p>We define multiple function signatures to use function overloads above the actual function implementation. Each signature is specific to a set of arguments and the expected return type. The function implementation follows these signatures and handles different cases accordingly.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">// Function signature for adding numbers and returning a number</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a: <span class="hljs-built_in">number</span>, b: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span></span>;

<span class="hljs-comment">// Function signature for concatenating strings and returning a string</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a: <span class="hljs-built_in">string</span>, b: <span class="hljs-built_in">string</span></span>): <span class="hljs-title">string</span></span>;

<span class="hljs-comment">// Function implementation that handles both cases</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a: <span class="hljs-built_in">any</span>, b: <span class="hljs-built_in">any</span></span>): <span class="hljs-title">any</span> </span>{
  <span class="hljs-keyword">return</span> a + b;
}
</code></pre>
<p>Let's consider one more example.</p>
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">convertToUnit</span>(<span class="hljs-params">value: <span class="hljs-built_in">number</span>, convertToString?: <span class="hljs-built_in">boolean</span></span>) </span>{
  <span class="hljs-keyword">if</span> (convertToString) <span class="hljs-keyword">return</span> value.toString();
  <span class="hljs-keyword">return</span> value;
}
</code></pre>
<p>In the above function, <code>convertToUnit</code> returns a union type of <code>string | number</code>, which loses the intellisense and other TS benefits. To overcome this, we can add the function signature for the functions based on <code>convertToString</code> the parameter value.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">// Will return string if convertToString is true</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">convertToUnit</span>(<span class="hljs-params">value: <span class="hljs-built_in">number</span>, convertToString: <span class="hljs-literal">true</span></span>): <span class="hljs-title">string</span></span>;

<span class="hljs-comment">// will return number if convertToString is false</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">convertToUnit</span>(<span class="hljs-params">value: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">number</span></span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">convertToUnit</span>(<span class="hljs-params">value: <span class="hljs-built_in">number</span>, covertToString?: <span class="hljs-built_in">boolean</span></span>) </span>{
  <span class="hljs-keyword">if</span> (covertToString) <span class="hljs-keyword">return</span> value.toString();
  <span class="hljs-keyword">return</span> value;
}
</code></pre>
<p>The <code>convertedStringValue</code> would have all the intellisense for strings and <code>convertedNumValue</code> all the intellisense for numbers.</p>
<p><a target="_blank" href="https://www.typescriptlang.org/play?#code/PTAEDEFcDsGMBcCWB7aoDOiDm0CG9IAnAU1ADNlDRcATGxaLUaSAWwCNjD1robQSBQtAZNczNp0IAoMjAQo0tGgApcALgkcuAGlDtNLbYQCUhyVwDc06SAjykqDNjxDSFKrFSx8xV6Ix4QlEeXD4BYiERRmpA4MZZB0VqOjVNdCDRPQM40TNcxmtbMCg4RzREVgAHABtiVj94fGT4AAt8UHa+Op52ZDbQH3RidESy5OU03gBPbM0w6fyF0ABvaVAIqNiAan1rAF8bOwB1RBqazaI0DPimRDJB1AA3LngAFWQAZUyYxB4gyDEMYKJxeaAvQjvZAAVRE8BUT1wNUB5mMejBEKh31umgBxHyN1ERTsAHczhdBFctFJQPdHuDXh9sQE-uQkcNgeV6ZiPrDEPDEcjiKipPkjFIinJxqDnoyYXCEUiUdTdI8eV8flgAPyaPrIOphEyrda0h4qLzq5mMI2U4SgQWAgB08A1txUJmsG1taAdxAONjBGW5r2INCtWAAakrSABeYOQ3kKgCMAAY9HiPcUNtmAHpagOoIMYkM0ABybCjQtAceLCfl-JUqczdmzoDzNmkQA">TS Playground</a></p>
]]></content:encoded></item><item><title><![CDATA[Tooltip using only CSS]]></title><description><![CDATA[Using a tooltip is a great way to pass information to the user in a very minimal and efficient way. It reduces the contents from the page which is important to show but not needed to show all the time.
  But when it comes to adding tooltips to the we...]]></description><link>https://script.thoughtlessmind.dev/tooltip-using-only-css</link><guid isPermaLink="true">https://script.thoughtlessmind.dev/tooltip-using-only-css</guid><category><![CDATA[CSS]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[styling]]></category><dc:creator><![CDATA[Rajiv Kumar]]></dc:creator><pubDate>Fri, 15 Jan 2021 19:51:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1610738632203/IRYtQ3nrw.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Using a tooltip is a great way to pass information to the user in a very minimal and efficient way. It reduces the contents from the page which is important to show but not needed to show all the time.</p>
<p>  But when it comes to adding tooltips to the website, developers generally use a library for this, which is definitely good as it gives a lot of customizations and controls. But in a situation when tooltips are required but not on a large scale instead, in certain places on the page, then it kinda feels useless to carry around such big libraries for this.  </p>
<hr />
<blockquote>
<p><em>Required Knowledge:-</em></p>
<ul>
<li><em>General working knowledge of <code>HTML</code> and <code>CSS</code></em></li>
<li><em>How <code>data</code> attribute works in HTML and CSS. For reference check <a target="_blank" href="https://css-tricks.com/a-complete-guide-to-data-attributes/#styling">this CSS-tricks article</a></em>  </li>
<li><em>Understanding of pseudo-selectors in CSS</em></li>
</ul>
</blockquote>
<hr />
<p>  There are several ways to create a tooltip in CSS. In this, we'll be using <code>pseudo-selectors</code> of CSS. One benefit of using this method is that there's no need to create an actual element in the HTML.<br />  First of all on whichever element you want to show the tooltip, add a <code>data</code> attribute <code>data-customTooltip="Tooltip text"</code>. Also, pass the text you wanna show on the tooltip.</p>
<blockquote>
<p>index.html</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">data-customTooltip</span>=<span class="hljs-string">"Tooltip text"</span>&gt;</span>
  Hover on me to see tooltip
<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
</blockquote>
<p>That's it, this is all we need in HTML. Now, let's add CSS to it. Here we'll be styling the tooltip using data attribute selector. <a target="_blank" href="https://css-tricks.com/a-complete-guide-to-data-attributes/#styling">Read here</a> more about it.</p>
<blockquote>
<p>styles.css  </p>
</blockquote>
<pre><code class="lang-css"><span class="hljs-selector-attr">[data-customTooltip]</span>{
    <span class="hljs-attribute">cursor</span>: pointer;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-attr">[data-customTooltip]</span><span class="hljs-selector-pseudo">::after</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fff</span>;
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#222</span>;
    <span class="hljs-attribute">font-size</span>:<span class="hljs-number">14px</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">8px</span> <span class="hljs-number">12px</span>;
    <span class="hljs-attribute">height</span>: fit-content;
    <span class="hljs-attribute">width</span>: fit-content;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">6px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">text-align</span>: center;
    <span class="hljs-attribute">bottom</span>: <span class="hljs-number">0px</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">content</span>: <span class="hljs-built_in">attr</span>(data-customTooltip);
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>, <span class="hljs-number">110%</span>) <span class="hljs-built_in">scale</span>(<span class="hljs-number">0</span>);
    <span class="hljs-attribute">transform-origin</span>: top;
    <span class="hljs-attribute">transition</span>: <span class="hljs-number">0.14s</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">14px</span> <span class="hljs-number">0</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,.<span class="hljs-number">2</span>), <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">1px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,.<span class="hljs-number">05</span>);
  }
</code></pre>
<p>Here, we're selecting the elements which have data-customTooltip attribute on them and creating a pseudo-element using :after. Till now a pseudo-element for the tooltip is created but it's not visible as there is scale(0) in the style.   </p>
<p> Now change the scale to 1 on hover on the parent element.</p>
<blockquote>
<p>style.css</p>
<pre><code class="lang-css">  <span class="hljs-selector-attr">[data-customTooltip]</span><span class="hljs-selector-pseudo">:hover</span><span class="hljs-selector-pseudo">:after</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>, <span class="hljs-number">110%</span>) <span class="hljs-built_in">scale</span>(<span class="hljs-number">1</span>);
  }
</code></pre>
</blockquote>
<p>And here is our tooltip....<br />Position can be changed according to requirement by giving suitable <code>top</code>, <code>left</code>, <code>bottom</code>, and <code>right</code> values along with translate property.<br /><em>I'll be writing another blog where we'll make the position of the tooltip dynamic and also incorporate light and dark themes.</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1610738524318/TO87qEe7p.gif" alt="tooltipDemo.gif" /></p>
<p>Now just pass <code>data-customTooltip="tooltip text"</code> attribute wherever you want to add a tooltip.</p>
<blockquote>
<p>Codepen demo  </p>
</blockquote>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/thoughtlessmind/pen/rNMoLWo">https://codepen.io/thoughtlessmind/pen/rNMoLWo</a></div>
<hr />
<p>PS:- <em>This is my first blog, if there's any mistake I'm making or there's any scope of improvement, please feel free to comment.</em>😀</p>
]]></content:encoded></item></channel></rss>