← Trail· Lesson 4 of 10
See this lesson in JavaScript →
Decisions
Choose paths with if/else and switch and restrict answers with literal and union types.

A decision picks the next step from a condition. numero % 2 === 0 tells whether an integer is even, including zero and negatives. The example uses a simplified teaching rule: age ≥ 16 → may vote.
Literal and union types
A string can be a type: 'par' (even) is a literal type. A union of literals is a closed list of valid answers:
type Paridade = 'par' | 'impar';
A function returning Paridade can only return 'par' or 'impar'; a typo such as 'Par' becomes a type error before any test runs. With type Dia = 'sabado' | 'domingo' | 'segunda', the editor suggests the switch cases and flags impossible ones.
Try it
Change idade, numero and dia. Setting dia to 'feriado' would be a type error in a TypeScript editor.
Execute o código para ver a saída aqui.Exercise
classificarNumero(numero: number): Paridade must return 'par' or 'impar'. The returns are swapped; fix them with if/else. Verificar includes zero and a negative integer. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o TypeScript e clique em Verificar.
Next step
Decisions choose paths; loops repeat one. Next we combine both in FizzBuzz.