TypeScript inherits all Pureline JavaScript rules.

PL-TS-001

Avoid any

Avoid typescript
function load(value: any): any {
}
Prefer typescript
function load(value: UserId): User {
}

Use unknown for truly unknown data:

typescript
function parse(input: unknown): Config {
}
PL-TS-002

Use Types Deliberately

Both inferred and explicit local types are Pureline-compliant.

typescript
const user = loadUser();

is valid when the inferred type is obvious.

Explicit typing is equally valid typescript
const user: User = loadUser();

Pureline does not treat an explicit annotation as redundant merely because TypeScript could infer it.

Explicit types are especially useful when they:

  • make intent clearer
  • document an expected contract
  • protect a boundary from unintended widening
  • improve refactoring confidence
  • make code easier to understand without following an entire call chain

Type inference should remove noise. It should never become a rule against using TypeScript's type system.

PL-TS-003

No Java-Style I Prefix

Preferred typescript
interface Session {
}
Not typescript
interface ISession {
}

The I prefix remains a Java-specific Pureline convention.

PL-TS-004

interface vs type

Use interface for object-like contracts:

typescript
interface User {
    id: string;
    name: string;
}

Use type for unions, aliases, and callable shapes:

typescript
type SessionState = "ready" | "closed" | "failed";
typescript
type Handler = (packet: Packet) => Promise<void>;
PL-TS-005

Prefer Union Types Over Enums When Appropriate

Preferred typescript
type State = "idle" | "ready" | "closed";

Use an enum only when an actual enum construct provides value.

PL-TS-006

Strong Types at Boundaries, Freedom Internally

Public APIs, external data, persistence boundaries, and network payloads should normally expose clear types.

Inside an implementation, both explicit annotations and inference are valid. Choose the form that makes the code easiest to understand. Pureline does not score one as cleaner purely because it contains fewer type annotations.