In TypeScript, if you do this:


function canDo(maybe = false) {
    console.log(maybe)
}
canDo(123)

it will complain, with


Argument of type '123' is not assignable to parameter of type 'boolean | undefined'.(2345)

That's because it infers argument maybe to be a boolean.

In Python, with mypy and ty it is not so. For example:


def can_do(maybe = False):
    print(maybe)

can_do(123)

Neither ty or mypy will complain about this. Curious.

To "fix" the problem with ty and mypy you have to explicitly state the type, like this:


def can_do(maybe: bool = False):
    print(maybe)

can_do(123)

Now, you'll get a warning on the can_do(123) which is


Argument 1 to "can_do" has incompatible type "int"; expected "bool"  [arg-type]

I'm sure there's a good explanation for the design choice but I don't know it. For right now, I'm just trying to remember that TypeScript != Python-with-types and that if I want to be more certain of types, I can't rely on inference like I can in TypeScript.

Previous:
Find the source of an alias in bash September 29, 2025 Linux, Bash, macOS
Next:
hylite as an executable October 15, 2025 Linux, Bun, TypeScript
Related by category:
Claude Opus is 10x faster than OpenAI GPT 5 at non-streaming completions July 24, 2026 Python
Best Django Redis configuration for speed and size July 19, 2026 Python
Benchmarking oxlint vs biome December 12, 2025 TypeScript
How to use a list/tuple/array in Django with a raw SQL cursor July 14, 2026 Python
Related by keyword:
In TypeScript, how to combine known and unknown keys to an object July 3, 2024 JavaScript
Run TypeScript in Node without extensions December 10, 2024 Node, JavaScript
How to extend a function in TypeScript without repeating the signature types October 16, 2024 JavaScript
Node watch mode and TypeScript July 21, 2024 Node, JavaScript