← Trail· Lesson 9 of 10
See this lesson in JavaScript →
Debugging and edge cases
See which mistakes the type checker catches, read console errors and fix an off-by-one loop.

Debugging investigates the gap between expected and observed behavior.
| Mistake | Caught by types? |
|---|---|
somarAte('3'), text instead of number |
Yes, before running |
aluno.nota instead of aluno.notas |
Yes |
Returning 'Par' for type 'par' | 'impar' |
Yes |
< instead of <= in a loop |
No: still a number |
Types remove a whole family of bugs, but a logic error produces a correctly typed wrong value. Use small inputs, console.log and tests. In this playground types are stripped before running; full type checking happens in your TypeScript editor.
Try it
The example should sum 1 + 2 + 3 = 6 but returns 3. Follow i and total in the Console.
Execute o código para ver a saída aqui.Exercise
somarAte(limite: number): number must sum integers from 1 through the limit, inclusive; zero or negative gives 0. The starter excludes the final number: fix the condition. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o TypeScript e clique em Verificar.
Next step
The final project combines everything in a typed average calculator.