{"record":{"id":"3a03107f0c5853be","repo":"biomejs/biome","slug":"promise-constructor-executor-must-be-a-function-type","errorCode":null,"errorMessage":"Promise constructor executor must be a function type","messagePattern":"Promise constructor executor must be a function type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xtask/codegen/src/generate_global_types/lower.rs","lineNumber":1103,"sourceCode":"fn validate_promise_construct_signature(member: &TsConstructSignatureTypeMember) -> Result<()> {\n    single_type_parameter_name(member.type_parameters(), \"Promise constructor\")?;\n\n    let mut parameters = member.parameters()?.items().into_iter();\n    let executor = required_formal_parameter(\n        parameters.next(),\n        \"Promise constructor\",\n        \"one executor parameter\",\n    )?;\n    if parameters.next().is_some() || executor.question_mark_token().is_some() {\n        bail!(\"Promise constructor must have one required executor parameter\");\n    }\n    let executor_type = executor\n        .type_annotation()\n        .context(\"Promise constructor executor is missing a type annotation\")?\n        .ty()\n        .context(\"Promise constructor executor has a malformed type annotation\")?;\n    let AnyTsType::TsFunctionType(executor) = executor_type else {\n        bail!(\"Promise constructor executor must be a function type\");\n    };\n    if executor.type_parameters().is_some() {\n        bail!(\"Promise constructor executor must not be generic\");\n    }\n    let executor_return_type = regular_return_type(executor.return_type()?, \"Promise constructor\")?;\n    if !matches!(executor_return_type, AnyTsType::TsVoidType(_)) {\n        bail!(\"Promise constructor executor must return void\");\n    }\n\n    let return_type = member\n        .type_annotation()\n        .context(\"Promise constructor is missing a return type\")?\n        .ty()\n        .context(\"Promise constructor has a malformed return type\")?;\n    validate_promise_reference(&return_type, \"Promise constructor\")\n}\n\n/// Requires `Promise<...>` without constraining the declaration's projected type argument.","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/biomejs/biome/blob/3835945f0638c88162351318b7bc8b64c5f2fba7/xtask/codegen/src/generate_global_types/lower.rs#L1085-L1121","documentation":"The executor parameter of the Promise construct signature must itself be a TS function type (e.g. `(resolve, reject) => void`). Codegen bails if the executor's annotated type is anything else — a reference, union, or non-function type — because the lowering step needs to inspect the executor's parameters and return type to synthesize the constructor helper.","triggerScenarios":"Running global-types codegen when the executor parameter is annotated as e.g. `Executor` (a type alias), `Function`, a union like `(resolve, reject) => void | undefined`, or any AnyTsType other than TsFunctionType.","commonSituations":"Replacing the inline executor function type with a named alias while refactoring the bundled declaration; upstream declarations using a different shape; a typo in the annotation.","solutions":["Inline the executor as a direct function type: `executor: (resolve: ..., reject: ...) => void`","If an alias is preferred, keep the function type inline in the validated declaration (aliases are not resolved by this validator)","Check that the annotation parses as a TsFunctionType in the AST rather than a TsReferenceType"],"exampleFix":"// before\nnew <T>(executor: Executor<T>): Promise<T>;\n// after\nnew <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void): Promise<T>;","handlingStrategy":"validation","validationCode":"// The executor must be an inline function type\nlet sig = \"executor: (resolve: (v: T) => void, reject: (e?: unknown) => void) => void\";\nassert!(sig.starts_with(\"executor: (\"), \"executor must be an inline function type, not an alias\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inline the executor's function type rather than referencing an alias","Avoid unions or wrapper types on the executor annotation","Verify AST shape (TsFunctionType) when changing how the executor is written"],"tags":["rust","codegen","typescript","globals"],"backgroundTag":"internal-invariant-violation","analyzedSha":"3835945f0638c88162351318b7bc8b64c5f2fba7","analyzedAt":"2026-09-13T15:11:16.919Z","contentChangedAt":"2026-09-13T15:11:16.919Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}