type safety
/taɪp ˈseɪf.ti/noun
Type safety is the extent to which a programming language prevents values from being used in ways incompatible with their types. Checks can identify such errors during coding, compilation or execution.
Type safety allowed the compiler to report that the function expected a number rather than text.
A type describes the kind of value a program processes, such as text, a number or a customer record. Type safety helps enforce which operations are valid for that value. A type check may report code trying to add text to a number or read a missing field.
When are types checked?
With static type checking, a compiler or other tool checks types before the software runs. Developers can find many errors while writing or building code. TypeScript adds this form of checking to JavaScript, for example.
Dynamic type checking determines whether an operation is valid during execution. A language can therefore be type-safe without finding every type error in advance. Strictness also depends on the language and configuration. Some systems deliberately allow type checks to be bypassed in particular places.
What type safety checks
Type safety concerns mismatches between values and operations. A function expecting a customer number might reject a complete customer object. These explicit agreements help reveal errors when code changes.
The checks do not prove that software is logically correct. A calculation can receive valid numbers yet produce the wrong result. Data from a form, Glossary · In briefAPIAn API is a defined way for software to exchange data or call functions in other software without needing to know how that software works internally.Read more or Glossary · In briefdatabaseA database is a structured collection of data that software can store, retrieve and modify. A database management system controls access to that data.Read more also needs validation at runtime: a static type does not automatically mean external data conforms to it. Type safety is therefore usually combined with tests and validation.