biomejs/biome · error
{} must not be optional
Error message
{} must not be optional What it means
validate_promise_methods checks each selected Promise method (matched by name and location against PROMISE_METHOD_SPECIFICATIONS). If a matching method carries an `?` optional token, the lowering rejects it because required members are assumed non-optional; the error names the method via specification.global_name.
Source
Thrown at xtask/codegen/src/generate_global_types/lower.rs:1005
| AnyTsTypeMember::TsCallSignatureTypeMember(_)
| AnyTsTypeMember::TsConstructSignatureTypeMember(_)
| AnyTsTypeMember::TsIndexSignatureTypeMember(_) => {}
}
}
Ok(())
}
/// Marks a selected method after checking the Promise return retained by the projection.
fn validate_selected_promise_method(
method: &TsMethodSignatureTypeMember,
location: PromiseMemberLocation,
saw_methods: &mut [bool; PROMISE_METHOD_COUNT],
) -> Result<()> {
let Some((index, specification)) = selected_promise_method(method.name()?, location)? else {
return Ok(());
};
if method.optional_token().is_some() {
bail!("{} must not be optional", specification.global_name);
}
let return_type = method
.return_type_annotation()
.with_context(|| format!("{} is missing a return type", specification.global_name))?
.ty()
.with_context(|| format!("{} has a malformed return type", specification.global_name))?;
let return_type = regular_return_type(return_type, specification.global_name)?;
validate_promise_reference(&return_type, specification.global_name)?;
saw_methods[index] = true;
Ok(())
}
/// Resolves a literal member name only within its instance or static declaration side.
fn selected_promise_method(
name: AnyJsObjectMemberName,
location: PromiseMemberLocation,
) -> Result<Option<(usize, PromiseMethodSpecification)>> {
let AnyJsObjectMemberName::JsLiteralMemberName(name) = name else {View on GitHub (pinned to 3835945f06)
Solutions
- Remove the `?` optional token from the method declaration in the lib sources
- Relax the optional check in lower.rs if optionality is now acceptable
- Regenerate the snapshot from upstream lib.d.ts where the method is required
Example fix
// before
interface Promise<T> { finally?(onfinally: () => void): Promise<T>; }
// after
interface Promise<T> { finally(onfinally: () => void): Promise<T>; } Defensive patterns
Strategy: validation
Validate before calling
for (const m of promiseDecl.members) {
if (m.optional && REQUIRED_METHODS.includes(m.name)) {
throw new Error(`Required Promise method '${m.name}' must not be optional`);
}
} Prevention
- Never mark required Promise methods with `?` in snapshots
- Reject optional tokens on known-good method names in a pre-codegen lint
- Regenerate snapshots from upstream sources instead of hand edits
When it happens
Trigger: Running generate_global_types when a required Promise method is declared optional in the lib sources, e.g. `finally?: (...) => Promise<T>;` or an optional method signature.
Common situations: Hand-edited snapshots marking methods optional for stricter consumer checks; tooling that converts method signatures to optional properties.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- type aliases are not supported in PromiseConstructor
- value-side PromiseConstructor declarations are not supported
- PromiseConstructor extends clauses are not supported
- PromiseConstructor type parameters are not supported
- PromiseConstructor must include an interface declaration
AI-assisted analysis of biomejs/biome@3835945f06 (2026-09-13).
Data as JSON: /api/errors/4d9fa26daeaaa92e.
Report an issue: GitHub.