Skip to main content

TypeScript Best Practices

Leverage TypeScript's type system for safety and clarity.

No any Type

Always use specific types or unknown when type is truly unknown.

Explicit Return Types

Annotate function return types for clarity.

Interfaces Over Types

Use interfaces for object shapes:

interface FundEntity {
id: number;
name: string;
code: string;
}

Type Guards

Use type guards for safe type narrowing:

function isFund(entity: unknown): entity is FundEntity {
return typeof entity === "object" && entity !== null && "code" in entity;
}

See Coding Standards for more details.