Lesson 2 · Unit 04
Types and linters
Checks that read your code without running it, and what they miss
What you practise
- What a type checker catches before any test runs, what it can't,
anyas an escape hatch, linters and formatters, the layers of defence
Try a question from this lesson
Pick one
A width arrives as text from a form field. No error is raised anywhere. What does this print?
def area(w, h):
return w * h
print(area("3", 4))function area(w, h) {
return w * h;
}
console.log(area("3", 4));function area(w: number, h: number) {
return w * h;
}
const input: any = "3";
console.log(area(input, 4));Correct answer
3333
12
12
Why
Python repeats the text four times; JavaScript quietly turns it into a number. Neither complains, and a caller who mixed up the kinds of value never finds out. A type checker reports this call before the program runs.
Python noteType hints such as w: float, read by a checker like mypy or pyright, report this call without running it. Python itself ignores hints at run time.
JavaScript notePlain JavaScript has no type checker. TypeScript adds one, and it can also check .js files that describe their types in JSDoc comments.
TypeScript noteany switches the checker off for that value. Without it, area("3", 4) does not compile, which is the whole point of the types.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Checks that never run your code
Some tools find mistakes by reading code instead of running it.
A type checker proves that each value is the kind its user expects: no text where a number belongs, no missing argument.
A linter flags patterns that are usually mistakes: a variable never used, a line that can never run.
Both are fast and cover every line, even lines no test visits. Neither knows what your program is supposed to do.
10 more exercises in the app
- 5× multiple choice
- 1× fill the blanks
- 1× true or false
- 1× type the answer
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.