TypeScript 5.3 launches today
(20 November 2023)

Other recent news...

Microsoft highlights .NET 8 Hardware Intrinsics features
Additional hardware functionality via APIs so the bespoke web apps we develop can take advantage of users' underlying hardware, e.g. WebAssembly support so that core algorithms can...
11 December 2023
Google launches Gemini AI model
Gemini was designed for flexibility, so it can run on everything from data centres to mobile devices. It's been optimized for three different sizes: Ultra, Pro and Nano (for on-dev...
6 December 2023
Apple launches release candidate versions of iOS 17.2 & iPadOS 17.2
Developing and testing our bespoke Apple iOS apps on beta versions of iOS 17.2 & iPadOS 17.2 allows our app developers to confirm that the apps we develop will work as expected...
5 December 2023
TypeScript 5.3 launches today
If you’re not familiar with TypeScript, it’s a language that adds type syntax to JavaScript to bring type-checking. Type-checking can catch all sorts of issues like typos and forgetting to check for null and undefined. But types go beyond type-checking – the same analyses of TypeScript’s type-checker are used for rich editor tooling like auto-completion, code navigation, and refactorings. In fact, if you’ve been writing JavaScript in editors like Visual Studio or VS Code, that experience is powered by TypeScript!

TypeScript is a superset of JavaScript that adds static typing to the language. It can be particularly beneficial for app developers as it helps catch errors during development, improves code maintainability, and provides better tooling support. Here are some ways app developers can use TypeScript along with detailed descriptions and code examples:

1. Setting up a TypeScript project:

Install TypeScript:

npm install -g typescript

Initialize a TypeScript project:

tsc --init

This creates a tsconfig.json file where you can configure TypeScript settings.

2. Basic TypeScript Types:

Example 1: Declaring variables with types

// basic types let username: string = "John"; let age: number = 30; let isDeveloper: boolean = true;

3. Functions and Interfaces:

Example 2: Function with type annotations

// function with type annotations function greet(name: string): string { return `Hello, ${name}!`; } console.log(greet("John")); // Output: Hello, John!

Example 3: Interfaces for object structures

// interface for an object interface Person { name: string; age: number; } // function using interface function printPerson(person: Person): void { console.log(`${person.name} is ${person.age} years old.`); } const user: Person = { name: "Alice", age: 25 }; printPerson(user); // Output: Alice is 25 years old.

4. Classes and Inheritance:

Example 4: Classes and inheritance

// class and inheritance class Animal { constructor(public name: string) {} makeSound(): void { console.log("Some generic sound"); } } class Dog extends Animal { makeSound(): void { console.log("Bark! Bark!"); } } const myDog = new Dog("Buddy"); myDog.makeSound(); // Output: Bark! Bark!

5. Generics:

Example 5: Using generics

// generic function function identity<T>(value: T): T { return value; } const result = identity<number>(42); console.log(result); // Output: 42

6. Modules and Namespaces:

Example 6: Modules

// module example // math.ts export function add(a: number, b: number): number { return a + b; } // app.ts import { add } from "./math"; const sum = add(3, 5); console.log(sum); // Output: 8

7. Type Declarations for External Libraries:

Example 7: Using external libraries with type declarations

// Example using Axios with TypeScript import axios from 'axios'; interface Post { userId: number; id: number; title: string; body: string; } axios.get<Post>('https://jsonplaceholder.typicode.com/posts/1') .then(response => { const post: Post = response.data; console.log(post.title); // Output: Post Title }) .catch(error => { console.error(error); });

These examples cover some of the fundamental aspects of using TypeScript in app development. Depending on the type of application (web, mobile, desktop), you may encounter additional features and patterns specific to those platforms.

more news...