A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/quizzes/generics-in-typescript-quiz/ below:

Quiz about Generics in TypeScript Quiz

What is the primary purpose of generics in TypeScript?

Which of the following is a correct example of a generic function?

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

What is the output type of the following generic function?

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

Which of the following defines a generic class?

TypeScript
class Box<T> {
    private content: T;
    constructor(content: T) {
        this.content = content;
    }
    getContent(): T {
        return this.content;
    }
}

What is the purpose of constraints in generics?

Which of the following constrains a generic type to objects with a length property?

TypeScript
function logLength<T extends { length: number }>(arg: T): void {
    console.log(arg.length);
}

What is the purpose of the Partial<T> built-in generic type in TypeScript?

How is the Record

generic type used in TypeScript?

What is the key difference between generics and type aliases?

Which of the following is a correct use of the ReadonlyArray<T> built-in generic type?

TypeScript
function printNumbers(numbers: ReadonlyArray<number>): void {
    numbers.forEach((num) => console.log(num));
    // numbers.push(10); // Error
}

There are 10 questions to complete.

Take a part in the ongoing discussion


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4