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 →Best PracticesBy default, TypeScript’s compiler doesn’t allow you to add a custom type annotation to an error in a try-catch statement (TS1196). That’s because the underlying code can throw any type of error, even system generated exceptions, which makes it impossible for TypeScript to know the error type from the start. Luckily, there is the concept called “type guards“ which can help the TypeScript compiler to infer a specific type.
Continue reading →ReactIt’s 2021 and TypeScript’s support for React apps improved by a lot. If you are new to TypeScript and React, you can learn from Amir Ghezelbash how to develop your first React app. In his tutorials, Amir starts from scratch and shows you on a weekly basis how to improve your React and TypeScript skills.
Continue reading →Best PracticesWhen developing class functions that don’t rely on an internal state, it’s a good idea to turn them into static methods. This can be easily done by adding the keyword static
to your function’s declaration.
Continue reading →Hands-OnSetting up a TypeScript project with Node.js takes only a few minutes. Here is how to do it the fastest way by just using npm
and yarn
.
Continue reading →TestingConfiguring code coverage with TypeScript and Karma to get coverage reports for code running in web browsers.
Continue reading →