# TypeScript code review checklist

> TypeScript code review checklist of the mistakes Revix checks for in pull requests, from non-null assertions to type casts used as runtime checks.

Canonical URL: https://www.revix.ai/checklists/typescript

The usual TypeScript code review trap is that types vanish at runtime. This checklist covers the mistakes Revix checks for in pull requests. Look for non-null assertions on unchecked values, request bodies cast to a type instead of validated, and DOM lookups cast instead of checked. Each rule shows the code to flag, the fix and its source.

Author: Oscar Estudillo · Updated: 2026-10-30

## 8 rules to check in every TypeScript pull request

### Validate runtime data explicitly

A TypeScript type describes what the compiler assumes, not what an incoming runtime value actually is.

**Avoid**

```typescript
const user = req.body as User;
return user.email.toLowerCase();
```

**Prefer**

```typescript
const user = UserSchema.parse(req.body);
return user.email.toLowerCase();
```

Flagged by Revix in real reviews · Security · All current versions · Source: [TypeScript for the New Programmer](https://www.typescriptlang.org/docs/handbook/typescript-from-scratch.html)

### Avoid unverified non-null assertions

The handbook says the operator does not change runtime behavior and is safe only when the value cannot be null or undefined.

**Avoid**

```typescript
function print(x?: number | null) {
  console.log(x!.toFixed());
}
```

**Prefer**

```typescript
function print(x?: number | null) {
  if (x == null) return;
  console.log(x.toFixed());
}
```

Flagged by Revix in real reviews · Security · All current versions · Source: [Everyday Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html)

### Do not rely on assertions for runtime validation

The handbook explicitly warns that assertions do not affect runtime behavior and do not generate an exception or null when the assertion is wrong.

**Avoid**

```typescript
const canvas = document.getElementById("main") as HTMLCanvasElement;
canvas.getContext("2d");
```

**Prefer**

```typescript
const node = document.getElementById("main");
if (!(node instanceof HTMLCanvasElement)) throw new Error("Expected canvas");
node.getContext("2d");
```

Flagged by Revix in real reviews · Security · All current versions · Source: [Everyday Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html)

### Make discriminated-union switches exhaustive

The never assignment turns an unhandled union member into a compile-time error when the union is later expanded.

**Avoid**

```typescript
switch (shape.kind) { case "circle": return area(shape); case "square": return area(shape); }
```

**Prefer**

```typescript
default: { const unreachable: never = shape; return unreachable; }
```

Flagged by Revix in real reviews · Best practice · All current versions · Source: [Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)

### Use children for element-only traversal

Processing childNodes as though every entry were an HTMLElement can include text nodes and produce incorrect traversal or runtime behavior.

**Avoid**

```typescript
for (const node of div.childNodes) {
  node.classList.add("item");
}
```

**Prefer**

```typescript
for (const element of div.children) {
  element.classList.add("item");
}
```

Flagged by Revix in real reviews · API usage · All current versions · Source: [DOM Manipulation — Difference between children and childNodes](https://www.typescriptlang.org/docs/handbook/dom-manipulation.html)

### Do not add unused generic parameters

The documentation states that type parameters should propagate type information and shows a generic length function whose single-use T is unnecessary.

**Avoid**

```typescript
function length<T extends ArrayLike<unknown>>(t:T): number { return t.length; }
```

**Prefer**

```typescript
function length(t: ArrayLike<unknown>): number { return t.length; }
```

Flagged by Revix in real reviews · API usage · All current versions · Source: [TypeScript for Functional Programmers](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html)

### Disallow angle-bracket type assertions in .tsx files

Using angle-bracket type assertions in .tsx files causes parsing ambiguities with JSX syntax, which could lead to compilation errors or unexpected behavior.

**Avoid**

```typescript
const foo = <Foo>bar;
```

**Prefer**

```typescript
const foo = bar as Foo;
```

Deprecation · All current versions · Source: [TypeScript JSX Documentation](https://www.typescriptlang.org/docs/handbook/jsx.html#the-as-operator)

### Replace deprecated amd-dependency directives

The directive is deprecated and can be replaced with the standard module dependency syntax.

**Avoid**

```typescript
/// <amd-dependency path="legacy/moduleA" />
```

**Prefer**

```typescript
import "legacy/moduleA";
```

Deprecation · All current versions · Source: [Triple-Slash Directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html)
