Previous in TypeScript
← TypeScript Fundamentals: Why JavaScript Developers Need TypesTypeScript Types, Inference and Functions
June 10, 2026
TypeScript Types, Inference and Functions
Primitive Types
TypeScript provides several built-in primitive types.
let username: string = "John";
let age: number = 25;
let isAdmin: boolean = false;
Type Inference
TypeScript often figures out types automatically.
let username = "John";
This process is called type inference.
Better Editor Support
Because TypeScript knows the type of a variable, editors can provide autocomplete and intelligent suggestions.
Compilation Still Happens With Errors
let age: number = "hello";
TypeScript reports an error, but JavaScript can still be generated depending on compiler settings.
The Any Type
let value: any = 10;
value = "hello";
value = true;
The any type disables type checking.
Implicit Any
let value;
When TypeScript cannot determine a type, it may infer any.
Function Parameters
function add(a: number, b: number) {
return a + b;
}
Return Types
function add(a: number, b: number): number {
return a + b;
}
Default Parameters
function greet(name: string = "Guest") {
return `Hello ${name}`;
}
Void
function logMessage(message: string): void {
console.log(message);
}
Contextual Typing
const colors = ["red", "green", "blue"];
colors.map(color => color.toUpperCase());
TypeScript infers that color is a string.
Never
function crash(message: string): never {
throw new Error(message);
}
A function returning never never successfully completes.
Summary
Type inference, function typing, any, void, and never form the foundation of everyday TypeScript development.