
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@babakness/exhaustive-type-checking
Advanced tools
This package exposes a helper type and three helper functions. Compare the switch pattern with those offered by this package.
This project was inspired by this StackOverflow question:
I wanted that didn't rely on switch and supported currying. So I cooked this up.
This package exposes a helper type and three helper functions. Compare the switch pattern with those offered by this package.
type Fruit = 'banana' | 'orange' | 'mango' | 'coconut'
export function makeDessert( fruit: Fruit ) {
switch( fruit ) {
case 'banana': return 'Banana Shake'
case 'orange': return 'Orange Juice'
case 'mango': return 'Mango Smoothie'
case 'coconut': return 'Coconut Ice Cream'
}
exhaustiveCheck( fruit )
}
matchConfigDeals with type limitations in TypeScript to partially assign generics. This is a function factory used to set the type expected by return function. Example use of the factory function:
const matchFruit = matchConfig<Fruit>()
The returned function is curried. It takes an object with lazily evaluated values and keys covering all possibilities for that type. To create the makeDessert function above, we would call matchFruit as follows:
const makeDessert = matchFruit({
'banana': () => 'Banana Shake'
'orange': () => 'Orange Juice'
'mango': () => 'Mango Smoothie'
'coconut': () => 'Coconut Ice Cream'
})
with the same exhaustive type checking afforded by the case-switch statement above approach above.
matchMatch is like matchConfig without the first function call. To make makeDessert we could provide the object first
const makeDessert = match({
'banana': () => 'Banana Shake'
'orange': () => 'Orange Juice'
'mango': () => 'Mango Smoothie'
'coconut': () => 'Coconut Ice Cream'
})
Then pass the variable with needed type information second
const dessert = makeDessert<Fruit>( 'banana' )
Or rely on the incoming variables type
function example( fruit: Fruit ) {
const dessert = makeDessert( fruit )
// ...
}
matchSwitchDesigned to be a direct replacement for the switch pattern.
export function makeDessert( fruit: Fruit ) {
return matchSwitch( fruit, {
'banana': () => 'Banana Shake',
'orange': () => 'Orange Juice',
'mango': () => 'Mango Smoothie',
'coconut': () => 'Coconut Ice Cream',
})
}
See the video tutorial for more details
FAQs
This package exposes a helper type and three helper functions. Compare the switch pattern with those offered by this package.
We found that @babakness/exhaustive-type-checking demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.