Tari Ibaba is a software developer with years of experience building websites and apps. He has written extensively on a wide range of programming topics and has created dozens of apps and open-source libraries.
Exciting news today as native TypeScript support finally comes to Node.js!
Yes you can now use types natively in Node.js.
So throw typescript and ts-node in the garbage.
❌Before now:
Node.js only ever cared for JavaScript files.
This would never have run:
Try it and you’d get this unpleasant error:
Our best bet was to install TypeScript and compile with tsc.
And millions of developers agreed it was a pretty good option:
But this was painful — having to install the same old package and type out the same command over and over again.
Extra compilation step to JS and having to deal with TypeScript configurations and stuff.
Pretty frustrating — especially when we’re just doing a bit of testing.
That was why ts-node arrived to try to save the day — but it still wasn’t enough.
We could now run the TypeScript files directly:
We could even start an interactive session on the fly like we’d do with the standalone node command:
And everyone loved it:
But it was still an extra dependency, and we still had to install typescript.
We still had more subtle intricacies to be aware of, like how to use ts-node for ES modules with the --esm flag:
✅Now:
All this changes now with all the brand-new upgrades now in Node:
Native built-in TypeScript support.
Zero dependencies
Zero intermediate files and module configurations
Now all our favorite JS tools like Prettier, Next.js, and Webpack can have safer and intellisense-friendly config files.
Okay almost no one has Webpack in their favorite tools list but still…
Look we already have pull requests like this to support prettier.config.ts in Prettier — and they’re going to be taking big steps forward thanks to this new development.
How does it work behind the scenes?
Support for TypeScript will be gradual, so right now it only supports types — you can’t use more TypeScript-y features like enums (although who uses enums these days).
It uses the @swc/wasm-typescript tool to internally strip the TypeScript file of all its types.
Early beginnings like I said, so it’s still experimental and for now you’ll need the --experimental-strip-types flag:
JavaScriptCopied!
node --experimental-strip-types my-file
This will be in an upcoming release.
Final thoughts
Built-in TypeScript is a serious power move to make Node.js a much more enjoyable platform for JS devs. I’ll definitely be using this.
Even though the support is not yet as seamless as in Bun or Deno, it makes a far-reaching impact on the entire JavaScript ecosystem as Node is still the most popular JS backend framework by light years.
Developers spend 75% of their time debugging and this is a major reason why.
Avoiding this mistake will massively cut down the bug occurrence rate in your code.
Never take new code for granted.
A simple but powerful principle with several implications.
Never assume your code works just because it looks alright
Always test your code in the real world.
And not just your machine.
You cannot trust your mind on this — That’s why bugs exist in the first place.
Bugs are always something you never expect.
It’s a big reason why debugging takes much time, especially for complex algorithms.
Your mental model of the code’s logic is hopelessly divorced from reality.
It’s often only when you carefully step through the code line-by-line & var-by-var before you finally realize the disconnect.
It’s the same reason why it can be so hard to proofread your own writing.
Your brain already knows what you meant to write. It has already created a mental model of the meaning you’re trying to convey that’s different from what’s actually there.
So what happens when you try re-reading your work for errors?
You’re far more focused on the overall intended meaning than the low-level grammatical and spelling errors.
That’s why code reviews are important — get your work scrutinized by multiple eyes that are new to the code.
That’s why testing regularly is important.
Test regularly and incrementally and you’ll catch bugs much faster and quicker.
As soon as you make a meaningful change, test it.
And this is where techniques of automated testing and continuous integration shine.
With manual testing you’ll be far more likely to procrastinate on testing until you’ve made huge changes — that are probably overflowing with bugs.
With continuous integration there’s no room for procrastination whatsoever.
As long as you commit regularly, you’ll drastically cut down on the bug turnaround time and the chances of something going horribly, mind-bogglingly wrong.
VS Code’s multi-cursor editing feature makes this even more powerful — with Ctrl + Alt + Down I easily select all the new elements to add text to all of them at the same time:
10. Lorem Ipsum
Lorem Ipsum is the standard placeholder text for designing UIs, and Emmet makes it effortless to add it for visual testing.
Just type lorem in VS Code and you’ll instantly a full paragraph of the stuff:
Type lorem again to expand the text — it intelligently continues from where it stopped:
Final thoughts
Use these 10 powerful Emmet syntax tips to write HTML and JSX faster than ever.
Prettier is a pretty😏 useful tool that automatically formats your code using opinionated and customizable rules.
It ensures that all your code has a consistent format and can help enforce a specific styling convention in a collaborative project involving multiple developers.
The Prettier extension for Visual Studio Code brings about a seamless integration between the code editor and Prettier, allowing you to easily format code using a keyboard shortcut, or immediately after saving the file.
ESLint is a tool that finds and fixes problems in your JavaScript code.
It deals with both code quality and coding style issues, helping to identify programming patterns that are likely to produce tricky bugs.
The ESLint extension for Visual Studio Code enables integration between ESLint and the code editor. This integration allows ESLint to notify you of problems right in the editor.
For instance, it can use a red wavy line to notify of errors:
We can view details on the error by hovering over the red line:
We can also use the Problems tab to view all errors in every file in the current VS Code workspace.
The Live Server extension for VS Code starts a local server that serves pages using the contents of files in the workspace. The server will automatically reload when an associated file is changed.
In the demo below, a new server is launched quickly to display the contents of the index.html file. Modifying index.html and saving the file reloads the server instantly. This saves you from having to manually reload the page in the browser every time you make a change.
As you saw in the demo, you can easily launch a new server using the Open with Live Server item in the right-click context menu for a file in the VS Code Explorer.
IntelliCode is another powerful AI tool that produces smart code completion recommendations that make sense in the current code context.
It does this using an AI model that has been trained on thousands of popular open-source projects on GitHub.
When you type the . character to access an object method or fields, IntelliCode will suggest a list of members that are likely to be used in the present scenario. The items in the list are denoted using a star symbol, as shown in the following demo.
IntelliCode is available for JavaScript, TypeScript, Python, and several other languages.
Icon packs are available to customize the look of files of different types in Visual Studio Code. They enhance the look of the application and make it easier to identify and distinguish files of various sorts.
VSCode Icons is one the most popular icon pack extensions, boasting a highly comprehensive set of icons and over 11 million downloads.
It goes beyond file extension differentiation, to provide distinct icons for files and folders with specific names, including package.json, node_modules and .prettierrc.
Final thoughts
These are 10 essential extensions that aid web development in Visual Studio Code. Install them now to boost your developer productivity and raise your quality of life as a web developer.
Here’s something most JavaScript developers don’t know:
You can shorten any piece of code into a single line.
With one-liners I went from 17 imperative lines:
JavaScriptCopied!
// ❌ 17 lines
function extractRedirects(str) {
let lines = str.split('\n');
let sourceDestinationList = [];
for (let line of lines) {
let sourceDestination = line.split(' ');
let source = sourceDestination[2];
let destination = sourceDestination[3];
let redirectObj = {
source: source,
destination: destination,
permanent: true,
};
sourceDestinationList.push(redirectObj);
}
return sourceDestinationList;
}
// For more complex objects
// and sort() will probably have a defined callback
const areEqual = (arr1, arr2) =>
JSON.stringify(arr1.sort()) === JSON.stringify(arr2.sort());
7. Remove duplicates from array
Shortest way to remove duplicates from an array?
❌ 9 lines:
JavaScriptCopied!
const removeDuplicates = (arr) => {
const result = [];
for (const num of arr) {
if (!result.includes(num)) {
result.push(num);
}
}
return result;
};
const arr = [1, 2, 3, 4, 5, 3, 1, 2, 5];
const distinct = removeDuplicates(arr);
console.log(distinct); // [1, 2, 3, 4, 5]
Countless operations jam-packed into a single statement; A race from input start to output finish with no breaks, a free flow of high-level processing. A testament of coding ability and mastery.
This is the power and beauty of JavaScript one-liners.
The new native nested CSS feature changes everything for frontend development and makes SASS & LESS useless.
❌ Before:
How would you style the nested elements in this HTML?
HTMLCopied!
<section>
Hi!
<div>
<p><span>codingbeautydev.com</span> -- coding as a passion</p>
Coding helps you achieve a sense of purpose and growth
</div>
</section>
You’d normally stress yourself and waste a lot of time repeating the outer element names.
No wonder SASS and LESS became so popular.
CSSCopied!
section {
font-family: Arial;
}
section div {
font-size: 1.5em;
}
section div p {
color: blue;
}
section div p span {
font-weight: bold;
}
✅ But now: with native CSS:
CSSCopied!
section {
font-family: Arial;
div {
font-size: 1.2em;
p {
color: blue;
span {
font-weight: bold;
}
}
}
}
So much cleaner and easier. All the styles are now encapsulated together instead of being scattered all over the place.
As intuitive as encapsulation in object-oriented programming:
JavaScriptCopied!
// ❌ redundancy
const personName = 'Tari Ibaba';
const personSite = 'codingbeautydev.com';
const personColor = '🔵blue';
// ✅ encapsulate field
class Person {
name = 'Tari Ibaba';
site = 'codingbeautydev.com';
color = '🔵blue';
}
It makes more intuitive sense for the element styles to contain query styles — than for the query styles to contain small segments of the element styles.