Type errors arise when values are used in ways incompatible with their types. Go tracks the type of every value and rejects mismatches at build time, catching many errors before deployment rather than waiting for a particular code path to run. section 1.2.2 section 5.0
Listing 1.2 Type mismatch caught at compile time
var number int var str string number = 1 str = "one" number = str // Error: cannot use str (variable of type string) as int in assignment
Assigning a string to an int fails at compilation, so the incompatible assignment cannot reach a running program. section 1.2.2
Type safety also supports domain modeling. Named types and structs represent measurements and recipes, while composition combines simpler types into richer ones. Interfaces and methods add shared behaviors such as scaling recipes and converting measurements. section 5.0 section 5.6.2
Generics let functions and types work across multiple data types while retaining compile-time type safety. They are useful when shared logic or a type relationship must be preserved, but a plain interface or concrete type can be clearer when genericity adds no real benefit. section 6.0 section 6.5.4










