Typescript Flashcards

(33 cards)

1
Q

O que é TypeScript?

A

Código transpilado para Javascript puro.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Qual comando é utilizado para compilar um arquivo TypeScript?

A

tsc arquivo.ts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

O que o TypeScript adiciona ao Javascript?

A

Tipagem estática.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Defina tipagem dinâmica.

A

Define o tipo de variável de acordo com o seu valor atual.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Defina tipagem estática.

A

Você tem que definir explicitamente o tipo da variável.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Qual é o arquivo de configuração do TypeScript?

A

tsconfig.json

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Quais são os tipos primários do Javascript?

A
  • number
  • string
  • bigint
  • boolean
  • symbol
  • null
  • undefined
  • object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Quais são os tipos primários do TypeScript?

A
  • any
  • unknown
  • never
  • void
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Como declarar uma variável do tipo number em TypeScript?

A

let age: number = 3;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Como declarar uma lista de números em TypeScript?

A

const ids: number[] = [1, 2, 3, 4, 5];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

O que é uma tupla em TypeScript?

A

Uma lista de elementos com tipos fixos.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Como declarar uma tupla em TypeScript?

A

const person: [number, string] = [1, “Davi”];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Como declarar uma lista de tuplas em TypeScript?

A

const people: [number, string][] = [[1, “Davi”], [2, “João”]];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

O que é uma intersection em TypeScript?

A

Permite combinar múltiplos tipos em um único tipo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Como declarar uma intersection em TypeScript?

A

const productId: number | null = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

O que é um enum em TypeScript?

A

Uma forma de definir um conjunto de constantes nomeadas.

17
Q

Como declarar um enum em TypeScript?

A

enum UserTypes { Admin = 1, Operator = 2 }

18
Q

O que é type assertion em TypeScript?

A

Uma forma de informar ao compilador o tipo de uma variável.

19
Q

Como fazer type assertion em TypeScript?

A

const secondVar = firstVar as string;

20
Q

Como declarar uma tipagem customizada em TypeScript?

A

type User = { id: number, name: string, age: number, email?: string }

21
Q

Como declarar um objeto do tipo User em TypeScript?

A

const user: User = { id: 1, name: “davi”, age: 33, email: “davi@davi.com” };

22
Q

O que é uma union em TypeScript?

A

Permite que uma variável tenha múltiplos tipos.

23
Q

Como declarar uma union em TypeScript?

A

type Author = { books: string[] };

24
Q

O que é uma interface em TypeScript?

A

Um contrato que define a estrutura de um objeto.

25
Como declarar uma interface em TypeScript?
interface UserInterface { readonly firstName: string; email: string; }
26
Como instanciar um objeto que implementa uma interface?
const adminUser: UserInterface = { firstName: "Davi", email: "davi@davi.com" };
27
O que é POO em TypeScript?
Programação Orientada a Objetos.
28
Como declarar uma classe que implementa uma interface em TypeScript?
class Person implements IPerson { ... }
29
Como declarar um construtor em uma classe em TypeScript?
constructor(id: number, name: string, age: number) { ... }
30
Como usar shorthand em uma classe em TypeScript?
constructor(readonly id: number, protected name: string, private age: number) { ... }
31
O que são generics em TypeScript?
Permitem criar funções ou classes que trabalham com múltiplos tipos.
32
Como declarar uma função genérica em TypeScript?
const returnValue = (value: T) => value;
33
Como declarar uma função que retorna uma Promise em TypeScript?
const returnPromise = async (): Promise => { return 5; }