type inference

The compiler working out a type from the code itself, so you do not have to write it out by hand.

In more detail

The type is still fixed once chosen; inference only saves typing, so code stays short while remaining statically typed. For example, a variable set to a string literal is given a string type without you writing it. An explicit type can still document an unusual case.

Examples

type UserDTO = z.infer<typeof UserSchema>
ratio := 0.75  // float64
Go: host := "db-1" infers string; ratio := 0.75 infers float64
Java: String answer = first("ready", "later"); var names = List.of("Ada", "Lin");
String answer = first("ready", "later");
var names = List.of("Ada", "Lin");

Related terms

Taught in

References

Certification courses