Skip to content
ZOLO / TE109 Type · error

cannot infer field type from its default value

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

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br