{"record":{"id":"0c290748ef638b9e","repo":"biomejs/biome","slug":"promise-constructor-executor-must-not-be-generic","errorCode":null,"errorMessage":"Promise constructor executor must not be generic","messagePattern":"Promise constructor executor must not be generic","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xtask/codegen/src/generate_global_types/lower.rs","lineNumber":1106,"sourceCode":"    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.\nfn validate_promise_reference(type_node: &AnyTsType, owner: &str) -> Result<()> {\n    let AnyTsType::TsReferenceType(reference) = type_node else {\n        bail!(\"{owner} must return Promise\");","sourceCodeStart":1088,"sourceCodeEnd":1124,"githubUrl":"https://github.com/biomejs/biome/blob/3835945f0638c88162351318b7bc8b64c5f2fba7/xtask/codegen/src/generate_global_types/lower.rs#L1088-L1124","documentation":"The executor function type must not declare its own type parameters. A generic executor like `<T>(resolve, reject) => void` cannot be modeled by the synthetic constructor helper, so codegen bails. The generic Promise parameter belongs on the construct signature, not on the executor.","triggerScenarios":"Running global-types codegen when the bundled declaration writes the executor as a generic function type, e.g. `new <T>(executor: <T>(resolve, reject) => void): Promise<T>`.","commonSituations":"Copy-pasting a signature from another library where the executor was generic; an over-eager edit adding `<T>` to the executor; merging upstream changes incorrectly.","solutions":["Remove the type-parameter list from the executor function type, leaving `executor: (resolve, reject) => void`","Keep the `<T>` generic parameter on the construct signature itself, where it belongs","Re-sync the bundled declaration if the drift came from upstream"],"exampleFix":"// before\nnew <T>(executor: <T>(resolve, reject) => void): Promise<T>;\n// after\nnew <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void): Promise<T>;","handlingStrategy":"validation","validationCode":"// Executor must not declare its own type parameters\nlet executor = \"(resolve: (v: T) => void, reject: (e?: unknown) => void) => void\";\nassert!(!executor.starts_with(\"<\"), \"executor must not be generic\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep generics on the construct signature, never on the executor function type","When copying signatures from other libraries, strip executor-level type parameters","Review merges of upstream declaration changes for accidental generic additions"],"tags":["rust","codegen","typescript","generics","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"}