← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

const Type Parameters (TS 5.0)

TypeScript 5.0 Intermediate
debt(d7/e1/b1/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate automated detection is 'no' and the only tool is the TypeScript compiler itself — but the compiler won't flag misuse (e.g. using const type params when widened types are needed). A developer must notice through code review that literal inference is undesired or that readonly was omitted; there's no linter rule or SAST catching these misuses automatically.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix confirms it's simply adding or removing the const modifier on a type parameter declaration — a trivial one-character/one-word change at the function signature level.

b1 Burden Structural debt — long-term weight of choosing wrong

Closest to 'minimal commitment' (b1). This is a type-level modifier on individual generic function signatures. It imposes no structural obligation on callers or the rest of the codebase — each usage is self-contained, and removing or adding it is a one-line change with no cross-cutting consequences.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly calls out that developers familiar with Rust confuse this with Rust's const generics (value-level computation), when TypeScript's version is purely about literal type inference. Additionally, common mistakes include confusing it with the const keyword and forgetting readonly for tuple preservation — documented gotchas that competent developers encounter and must learn.

About DEBT scoring →

TL;DR

TypeScript 5.0 const type parameters infer literal types instead of widened types — const T extends string[] infers ['a','b'] not string[].

Explanation

Without const, TypeScript widens inferred types: function identity<T>(x: T): T with identity(['a','b']) infers T as string[]. With const modifier: function identity<const T>(x: T): T infers T as readonly ['a', 'b']. This enables more precise inference without requiring 'as const' at the call site. Use cases: route definitions, action creators, tuple preservation. The const modifier on a type parameter is similar to inferring with as const. Works with object types too — properties become readonly with literal types.

Common Misconception

const type parameters are the same as const generics in Rust — TypeScript's const type params are about literal type inference, not value-level computation.

Why It Matters

const type parameters enable APIs that preserve literal types without requiring callers to add 'as const' everywhere — cleaner DX for library authors.

Common Mistakes

  • Using const type params when widened types are actually needed.
  • Not combining with readonly for tuple preservation.
  • Confusing with the const keyword — this is a type-level modifier.

Code Examples

✗ Vulnerable
function makeRoute<T extends string>(path: T) { return path; }
const r = makeRoute('/users'); // T inferred as string, not '/users'
✓ Fixed
function makeRoute<const T extends string>(path: T) { return path; }
const r = makeRoute('/users'); // T inferred as '/users' literal

// With arrays:
function tuple<const T extends unknown[]>(...args: T): T { return args; }
const t = tuple(1, 'two', true); // [1, 'two', true] not (number|string|boolean)[]

Added 23 Mar 2026
Views 56
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 1 ping T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 18 Google 7 Ahrefs 5 Perplexity 4 Scrapy 4 Unknown AI 3 SEMrush 3 Meta AI 2 Claude 2 PetalBot 2 ChatGPT 1
crawler 45 crawler_json 4 pre-tracking 2
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Add const modifier to type parameters when you want literal type inference. Useful for route builders, action creators, and tuple-returning utilities.
📦 Applies To
typescript 5.0 web cli
🔗 Prerequisites
🔍 Detection Hints
<const T
Auto-detectable: ✗ No typescript
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Low Context: Function


✓ schema.org compliant