Provides a helper function for checking exhaustiveness. Exhaustiveness checking is a feature of a language where the type checker guarantees that all cases were covered.
pnpm add @freckle/exhaustiveThis package is ESM-only.
import {exhaustive} from '@freckle/exhaustive'
type Status = 'success' | 'failure'
function getStatusMessage(status: Status): string {
switch (status) {
case 'success':
return 'The operation completed successfully.'
case 'failure':
return 'The operation failed.'
default:
return exhaustive(status)
}
}Usage in a reducer where returning the state itself in the default case is a common pattern:
import {exhaustiveReducer} from '@freckle/exhaustive'
type TodoState = {...}
type TodoAction = {type: 'todoAdded', ...} | {type: 'todoToggled', ...}
const defaultTodoState = {...}
function todoReducer(
state: TodoState = defaultTodoState,
action: TodoAction
): TodoState {
switch (action.type) {
case 'todoAdded':
return {...}
case 'todoToggled':
return {...}
default:
return exhaustiveReducer(action.type, state)
}
}- Package manager: pnpm (Node version pinned in
.nvmrc) pnpm build—tscviatsconfig.build.json; emits todist/pnpm test— Vitestpnpm coverage— Vitest with coverage, gated at 70% (lines/branches/functions/statements)pnpm typecheck—tsc --noEmit, includes test filespnpm lint— ESLintpnpm format/pnpm format-check— Prettierpnpm knip— unused files/dependencies/exports- CI runs all of the above on every PR, plus a check that
dist/is up to date
dist/ is committed. Run pnpm build before pushing.
See RELEASE.md for more details.