Concept Flow - Parameter type annotations
Function Declaration
Parameters with Types
Function Call with Arguments
Type Checking
Function Runs
This flow shows how TypeScript checks parameter types during function calls before running the function.
function greet(name: string) { return `Hello, ${name}!`; } console.log(greet("Alice"));
| Step | Action | Parameter 'name' Type | Argument Passed | Type Check Result | Output |
|---|---|---|---|---|---|
| 1 | Function greet declared | string | N/A | N/A | N/A |
| 2 | Call greet with argument "Alice" | string | "Alice" | Matches string | N/A |
| 3 | Function body executes | string | "Alice" | N/A | "Hello, Alice!" |
| 4 | console.log outputs result | N/A | N/A | N/A | Hello, Alice! |
| Variable | Start | After Call | Final |
|---|---|---|---|
| name | undefined | "Alice" | "Alice" |
| return value | undefined | undefined | "Hello, Alice!" |
Parameter type annotations in TypeScript:
function funcName(param: type) { ... }
- Specify expected type after parameter name
- TypeScript checks argument types at call
- Errors occur if types don't match
- Helps catch bugs before running code