Type hints are explicit annotations that declare expected types for values, parameters, properties, or return results. In TypeScript, they support maintainable code, API contracts, refactoring, and interview discussions about type safety. section 3.7
Use type hints to:
- Annotate basic values with types such as string, number, boolean, or any. section 3.7
- Annotate arrays, objects, and function signatures to make contracts explicit. section 3.7
- Improve IDE autocompletion, inline documentation, collaboration, and safer refactoring. section 3.6
- Balance explicit annotations with inference, adding declarations when they improve clarity or prevent ambiguity. section 3.7
Annotation versus unchecked flexibility
let vAny: any = 10; let vUnknown: unknown = 10; let s1: string = vAny; // allowed vAny.method(); // allowed let s2: string = vUnknown; // rejected vUnknown.method(); // rejected if (typeof vUnknown === "number") { let s3: string = vUnknown.toString(); } The comparison shows why a declared type can preserve safety: unknown requires narrowing or assertion before operations, while any disables checking. section 3.7
Table 3.5 Key features of TypeScript’s type system
|
Topic
|
Fundamentals
|
Applied skills
|
Advanced
|
|
Type annotations
|
Use basic types:
string,
number,
boolean,
any.
|
Annotate arrays, objects, and function signatures.
|
Design complex types with generics, conditional types, and mapped types for scalable APIs.
|
|
Type inference
|
Explain how TypeScript infers types.
|
Leverage inference for clean code; identify when explicit annotations improve clarity.
|
Debug inference pitfalls, architect type-safe APIs balancing inference and explicit types.
|
|
Structural typing
|
Understand duck typing and structural compatibility.
|
Compare interface vs type; use compatibility checks to refactor code safely.
|
Solve complex type compatibility issues; design extensible systems that leverage structural typing.
|
|
Union & intersection types
|
Use union (
|) and intersection (
&) types.
|
Model flexible APIs and handle discriminated unions.
|
Architect type-safe patterns with advanced unions and intersections.
|
|
Literal & enum types
|
Use string/number literals, define enums.
|
Model precise APIs, use
const enums for optimization.
|
Replace enums with union literals for safety; optimize enums for tree-shaking in bundles.
|
Review the progression from basic annotations to generic, conditional, and mapped types, alongside inference and structural typing. section 3.7





















