Structural and Compiler Rules
1. Arity and Type Enforcement When a function is invoked, the compiler checks both the arity (argument count) and the type compatibility. Omitting an argument for a required parameter, or providing an argument of the wrong type, results in a compile-time error (ts(2554) or ts(2345)).
2. Positional Constraints
In a function signature, required parameters must strictly precede any optional parameters (denoted by ?) or rest parameters (denoted by ...). A required parameter cannot follow an optional parameter because it creates ambiguity during positional argument resolution.
strictNullChecks
A required parameter dictates that an argument must be provided, but it does not inherently dictate that the value cannot be undefined. If a parameter must be provided but is allowed to be undefined, it must be typed with a union type.
Even if the type accepts undefined, the parameter remains structurally required; the invocation cannot be empty.
param: type = value) typically makes a parameter optional, this behavior changes based on positional context. If a default-initialized parameter precedes a required parameter, it is not treated as optional for the purpose of function application. The caller is strictly required to pass an argument (typically undefined to trigger the default value) for that position to satisfy the arity of the subsequent required parameter.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More





