Typescript: what is a “naked type parameter”

When they say naked here, they mean that the type parameter is present without being wrapped in another type, (i.e., an array, or a tuple, or a function, or a promise or any other generic type)

Ex:

type NakedUsage<T> = T extends boolean ? "YES" : "NO"
type WrappedUsage<T> = [T] extends [boolean] ? "YES" : "NO"; // wrapped in a tuple

The reason naked vs non naked is important is that naked usages distribute over a union, meaning the conditional type is applied for each member of the union and the result will be the union of all application

type Distributed = NakedUsage<number | boolean > // = NakedUsage<number> | NakedUsage<boolean> =  "NO" | "YES" 
type NotDistributed = WrappedUsage<number | boolean > // "NO"    
type NotDistributed2 = WrappedUsage<boolean > // "YES"

Read here about conditional type distribution.

Leave a Comment