Course contentsShow
← TypeScript
Lesson 1423 of 1,79632. Advanced PatternsFree lesson

When Not to Use const Type Parameters

Situations where const narrowing is too strict or unnecessary, and normal inference is preferred.

When Not to Use const Type Parameters

You'll learn: Sometimes const type parameters narrow types too aggressively, forcing you back to normal inference for flexibility and simplicity.


The Over-Narrowing Problem

const type parameters lock down literal types, which is powerful—but not always what you want. When you need a function to work generically across similar shapes without caring about exact literal values, const becomes a constraint rather than a feature.

When Normal Inference Is Better

1. Functions That Transform Types

If your function doesn't need to preserve exact literals—just work with the general type—normal inference keeps things simple:

// ❌ Too strict with const
function wrapInArray<const T>(value: T) {
  return [value];
}

const result1 = wrapInArray("hello");
// Type: ["hello"] - overly specific

// ✅ Normal inference is cleaner
function wrapInArray<T>(value: T) {
  return [value];
}

const result2 = wrapInArray("hello");
// Type: string[] - appropriately general

2. When Values Will Change

If the result gets mutated or combined with other data, literal precision becomes noise:

function createState<const T>(initial: T) {
  return { value: initial };
}

const state = createState(42);
// state.value is typed as 42
state.value = 100; // ❌ Error: Type '100' is not assignable to '42'

3. Generic Utilities Operating on Shapes

When you care about structure, not exact values, const adds complexity without benefit:

// Doesn't need const - we only care it's an object
function clone<T extends object>(obj: T): T {
  return { ...obj };
}

The Readability Trade-off

Deep literal types (readonly ["a", "b", { readonly x: 123 }]) hurt readability in errors and hover tooltips. If your team doesn't need that precision, normal inference keeps types manageable.


Key Takeaway: Use const type parameters when you need literal preservation for type safety (like routing or config). Skip it when you're building general utilities, working with mutable data, or when wider types improve ergonomics without sacrificing safety.