Why this fires¶
A struct field is written without a type annotation, relying on its default value to infer the type (name = value) — but the default's type can't be determined unambiguously (e.g. the default is nil, or another expression whose type resolves to any/unknown).
struct Config {
retries = 3,
timeout = nil,
// ^^^ error[TE109]: cannot infer the type of field 'timeout' from its
// default (annotate it explicitly, e.g. `timeout: <type> = ...`)
}Fix it¶
Annotate the field's type explicitly:
struct Config {
retries = 3, // ok — inferred as int
timeout: int? = nil, // ok — explicit optional type
}See also¶
TE108—@derive(Default)fails because a field's own type has noDefault.- /docs/data-structures#structs — struct field type inference from defaults.