Extract type-checking to support `namedtuple`.

Dunno whether it is a wide solution to support namedtuple :(