New FeaturesThe void operator, present in both TypeScript and plain JavaScript, evaluates an expression and returns undefined
. Although it may not initially seem particularly useful, the void operator plays a significant role in preventing unintended leakage of return values and handling Promises for side effects.
Continue reading →Best PracticesBranded types can help catch programming errors early in the development process by preventing values that don’t meet certain criteria from being passed into functions or used in certain contexts. They are a form of defensive coding in TypeScript and can ensure type validation.
Continue reading →Best PracticesDefensive code refers to a programming practice where a developer writes code that anticipates and handles potential issues or errors that might occur during the execution of a TypeScript application.
The goal of defensive coding is to improve the reliability, robustness, and maintainability of TypeScript applications by ensuring it can handle unexpected or incorrect input, recover gracefully from failures, and provide meaningful error messages or responses.
Continue reading →New FeaturesFunction overloading allows you to define multiple functions with the same name, but with different parameters. This can be useful if you want to provide different behavior depending on the arguments that are passed to the function.
Continue reading →Hands-OnIn this TypeScript tutorial we explore the significance of platform considerations when building a TypeScript application. We will discuss various JavaScript engines, configure the TypeScript compiler, enable strict type checking, and implement best practices for our development workflow using Visual Studio Code. We also cover TypeScript’s watch mode and how to write npm scripts. Lastly, we dive into potential issues that may arise when using TypeScript globally and how to define your VS Code’s TypeScript version.
Continue reading →Hands-OnIt is possible to use regular JavaScript code in a TypeScript application. TypeScript is a superset of JavaScript, which means that any valid JavaScript code is also valid TypeScript code. This allows developers to gradually adopt TypeScript by starting with their existing JavaScript codebase and gradually migrating it to TypeScript. Additionally, developers can use legacy JavaScript libraries and frameworks in a TypeScript application without any issues.
Continue reading →Best PracticesAn assertion function is the implementation of a runtime check that is able to identify the type of unknown input. When the conditions of the assertion functions are passed, TypeScript’s compiler will then assume that the input is of the type claimed by the signature of the assertion function.
Continue reading →New FeaturesTypeScript 2.1 introduced mapped types which allow you to build new types based on the properties of an existing type.
Continue reading →New FeaturesTypeScript 3.4 introduced const assertions, a feature that allows you to claim a value as immutable. This feature is particularly valuable in combination with array literals, as it prevents new values from being pushed into an existing array.
Continue reading →Hands-OnYou can extend your Express.js server easily with custom middleware. All you have to do is to write a function that accepts three parameters (req
, res
, next
).
Continue reading →