Skip to content
TE109 · Type · error

Cannot infer field type from its default

A struct field is written without a type annotation, relying on its default to infer the type (`name = value`) — but the default's type is ambiguous (e.g. `nil`, or an expression that resolves to `any`).

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

Search Zolo

9 results

en