In
computer science,
type safety is the extent to which a
programming language discourages or prevents
type errors. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing
data types for the program's constants, variables, and methods (functions), e.g., treating an integer (
int) as a floating-point number (
float). Type safety is sometimes alternatively considered to be a property of a computer program rather than the language in which that program is written; that is, some languages have type-safe facilities that can be circumvented by programmers who adopt practices that exhibit poor type safety. The formal
type-theoretic definition of type safety is considerably stronger than what is understood by most programmers.