any
, minimal unknown
, prefer discriminated unions over type casts).my-utility.ts
).fetchData
, isValidUser
).is
, can
, has
, or should
.any
. Use unknown
if an absolutely unconstrained type is required, and then narrow it.string | number
) and narrow them with if (typeof val === 'string') { ... }
.type: 'loading' | 'success' | 'error'
) for clear narrowing blocks.<T>
generics.<T extends object>
) to maintain correctness.as const
for immutable data or literal inferences.extends
, infer
, and keyof
responsibly.