If I haven’t misunderstood this completely, a constant or type can not be declared at the top level of a file. Only packages, entities, architectures et.c. can be declared there. They can be declared in the entity but not before the port and generic clauses.
Often you would want to define a type or constant for use in the port or generic clause of an entity but since this can’t be declared at the top level of the file and not inside the entity either, where should this be declared?
Typically these are declared in a package which is included at the beginning of your file, just as you would include the standard VHDL packages ie:
You may then use your custom types in port declarations and anywhere else in your entity.