<T>) and why are they useful?TypeScript - Advanced Types & Tooling
tsconfig.json options and the nuances between interface and type.Cards in this deck
(24 cards)Preview terms and definitions before starting your study session.
function identity<T>(arg: T): T {
return arg;
}
let output1 = identity<string>("myString"); // type of output1 is string
let output2 = identity<number>(100); // type of output2 is number
// Type argument inference often allows omitting <T>:
let output3 = identity("anotherString"); // type of output3 is stringinterface Box<T> {
value: T;
}
let stringBox: Box<string> = { value: "hello" };
let numberBox: Box<number> = { value: 123 };interface keyword in TypeScript.interface in TypeScript is used to define the shape of an object, specifying the names and types of its properties and methods. It acts as a contract that classes can implement or objects can conform to, ensuring type consistency.type keyword (type alias) in TypeScript.type alias creates a new name for an existing type. It can be used to define primitive types, union types, intersection types, tuples, and even complex object shapes, similar to interfaces.interface and type regarding declaration merging?interface supports "declaration merging," meaning if you declare multiple interfaces with the same name, TypeScript will merge them into a single interface. type aliases, however, do not support declaration merging; redeclaring a type with the same name will result in a compilation error.interface over a type alias?interface when defining the shape of an object, especially when you anticipate future extensions (e.g., via extends or declaration merging) or when implementing with classes (implements).type alias over an interface?type alias when defining primitive aliases, union types, intersection types, tuple types, or when you need to define a type that is not an object shape (e.g., type ID = string | number;).Related Flashcard Sets
Explore similar study materials created by the community
Korean TOPIK I - Basic Vocabulary & Grammar
Master essential Korean vocabulary and grammar for the TOPIK I exam with this high-yield flashcard deck, covering daily greetings, self-introductions, basic verbs, and fundamental sentence structures. Perfect for beginners aiming to build a strong foundation in conversational Korean.
BIO101 - Cell Biology & Genetics Fundamentals
Master the essentials of life with this comprehensive BIO101 flashcard deck! Explore cell structure, function, energy processes, and unravel the core principles of Mendelian and molecular genetics.
CompTIA Network+ (N10-008) - Network Infrastructure & Security
Master crucial CompTIA Network+ (N10-008) concepts, from OSI/TCP/IP models and network devices to IP addressing, core protocols, and wireless standards, to build and secure robust network infrastructures.
STAT101 - Introduction to Statistics & Probability
Master essential introductory statistics concepts with this high-yield deck covering descriptive statistics, core probability distributions, hypothesis testing procedures, and simple linear regression models.