Skip to content
RapidFinger — free online typing test

Typing tests

← All programming languages

TypeScript Coding Practice

Practice typing real code syntax, including brackets, punctuation, and indentation. Snippets are for typing practice only and are never executed.

Types, interfaces, and array methods

interface User {
    id: number;
    name: string;
    active: boolean;
}

const users: User[] = [
    { id: 1, name: "Ada", active: true },
    { id: 2, name: "Grace", active: false },
];

const activeNames: string[] = users
    .filter((user: User) => user.active)
    .map((user: User) => user.name);

console.log(activeNames);

Generic functions

function identity<T>(value: T): T {
    return value;
}

const label: string = identity<string>("typed safely");

console.log(label);

Interfaces and array methods

interface Product {
    id: number;
    name: string;
    price: number;
}

const products: Product[] = [
    { id: 1, name: "Notebook", price: 4.5 },
    { id: 2, name: "Pen", price: 1.25 },
];

const total = products.reduce(
    (sum, product) => sum + product.price,
    0
);

console.log(`Total: $${total.toFixed(2)}`);