DEV Community

Cover image for Quick tip about TypeScript and why to avoid these types
Benjamin🦸‍♂️Auzanneau™
Benjamin🦸‍♂️Auzanneau™

Posted on • Edited on

2 2

Quick tip about TypeScript and why to avoid these types

Avoid the non-primitive Number, String, Boolean, Object, and Symbol types in TypeScript.
All of them refer to non-primitive reference types.
Instead, prefer the corresponding primitive types.

let textToCheck: String = 'text';
console.log(typeof textToCheck); // 'string'
console.log(textToCheck === 'text'); // true

textToCheck = new String('text');
console.log(typeof textToCheck); // 'object'
console.log(textToCheck === 'text'); // false
Enter fullscreen mode Exit fullscreen mode

It's easy to failed your equality check with them.

There is also a performance part that I will not detail here. I recommend this article from mozilla which makes a performance comparison between a literal string and its object version in JavaScript.

That's it, make good use of it !


I'm not a native English speaker so, thanks in advance if you want to improve my article with correct syntax/grammar/sentences.

I can accept all kind remarks :)

Cover by JC Dela Cuesta on Unsplash

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more