1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is TypeScript?
A statically typed superset of JavaScript that compiles to plain JavaScript
What is type inference
A feature in TypeScript that allows the compiler to automatically assign types to variables and functions based on their values or usage.
List the 5 primitive types in TypeScript.
string, number, boolean, null, undefined
How do you declare a union type?
let id: number | string;
What is a function type?
A way to define the type of a function by specifying the types of its parameters and the return type. e.g. let log: (msg: string) => void;
How do you define an object type using an interface?
interface User {
name: string;
age: number;
}
What's the difference between interface and type?
interface
is better for objects and can be extended; type
is more flexible (can alias unions, primitives, etc.)
How do you define a class with properties in TypeScript?
class Person {
constructor(public name: string, private age: number) {}
}
What is a tuple in TypeScript?
A tuple in TypeScript is an array with a fixed number of elements where each element can be of a different type. This allows for more structured data representations.
let person: [string, number] = ["Alice", 25];
What is the any type used for?
To opt-out of type checking (not recommended).
What does the unknown
type represent?
A safer alternative to any
; must be type-checked before use.
How do you define a literal type?
let direction: "left" | "right"; A literal type in TypeScript is a type that specifies a specific set of string or numeric values that a variable can hold. For example, the type "left" | "right" allows only those two strings as valid values.
How do you create a generic interface?
interface Box<T> {
value: T;
}
What does Partial<T> do?
Makes all properties in T
optional.