Typescript

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards

What is TypeScript?

A statically typed superset of JavaScript that compiles to plain JavaScript

2
New cards

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.

3
New cards

List the 5 primitive types in TypeScript.

string, number, boolean, null, undefined

4
New cards

How do you declare a union type?

let id: number | string;

5
New cards

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;

6
New cards

How do you define an object type using an interface?

interface User {

name: string;

age: number;

}

7
New cards

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.)

8
New cards

How do you define a class with properties in TypeScript?

class Person {

constructor(public name: string, private age: number) {}

}

9
New cards

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];

10
New cards

What is the any type used for?

To opt-out of type checking (not recommended).

11
New cards

What does the unknown type represent?

A safer alternative to any; must be type-checked before use.

12
New cards

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.

13
New cards

How do you create a generic interface?

interface Box<T> {

value: T;

}

14
New cards

What does Partial<T> do?

Makes all properties in T optional.