DEV Community

Discussion on: More accurate the type, better the code

 
macsikora profile image
Pragmatic Maciej • Edited

Not often there will be a benefit.

const isCat = (animal: Animal): animal is Cat => animal.kind === 'Cat'
// vs
import {AnimalKind} from 'somewhere'
const isCat = (animal: Animal): animal is Cat => animal.kind === AnimalKind.Cat

The readability is a valid point only if the Enum represents something with not readable representation. For http codes I don't think somebody can have any problem, and naming 404 as NotFound really doesn't help.