{"record":{"id":"0f695d497dcff05c","repo":"facebook/flow","slug":"unexpected-function-parameter-param-type","errorCode":null,"errorMessage":"Unexpected function parameter ${param.type}","messagePattern":"Unexpected function parameter (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/flow-api-translator/src/TSDefToFlowDef.js","lineNumber":1023,"sourceCode":"          } else if (\n            param.type === 'ArrayPattern' ||\n            param.type === 'ObjectPattern'\n          ) {\n            return constructFlowNode<FlowESTree.FunctionTypeParam>({\n              type: 'FunctionTypeParam',\n              name: constructFlowNode<FlowESTree.Identifier>({\n                type: 'Identifier',\n                name: `$$param${i}$`,\n                optional: false,\n                typeAnnotation: null,\n              }),\n              optional: Boolean(param.optional),\n              typeAnnotation: Transform.TSTypeAnnotationOpt(\n                param.typeAnnotation?.typeAnnotation,\n              ),\n            });\n          } else {\n            throw new Error(`Unexpected function parameter ${param.type}`);\n          }\n        }),\n      };\n    }\n\n    static TSImportType(\n      node: TSESTree.TSImportType,\n    ): FlowESTree.TypeAnnotationType {\n      const source =\n        node.argument ??\n        (node.source == null\n          ? null\n          : ({\n              type: 'TSLiteralType',\n              loc: node.source.loc,\n              literal: node.source,\n            } as TSESTree.TSLiteralType));\n      if (source == null) {","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/packages/flow-api-translator/src/TSDefToFlowDef.js#L1005-L1041","documentation":"Thrown by flow-api-translator while converting TypeScript definitions to Flow definitions (TSDefToFlowDef.js). _partitionAndTranslateTSFunctionParams only maps function parameters that are Identifier, ArrayPattern, or ObjectPattern nodes (plus a leading `this` Identifier and a trailing RestElement). Any other ESTree parameter node type hits the bare `throw new Error`, which bypasses the recoverFromErrors machinery used elsewhere in the file.","triggerScenarios":"Calling unstable_translateTSDefToFlowDef on .d.ts code containing function/method signature parameters the translator does not model, e.g. `declare function f(a = 1): void` (AssignmentPattern), constructor parameter properties, or decorators on parameters. Only three param shapes are handled: Identifier, ArrayPattern, ObjectPattern.","commonSituations":"Converting real-world .d.ts files that use default-initialized parameters in declarations; TS interface method signatures with unusual param nodes; running codemods over large declaration bundles where one unhandled param aborts the whole translation.","solutions":["Rewrite the offending declaration to use an optional parameter instead of a default value, e.g. `declare function f(a?: number): void` instead of `declare function f(a = 1): void`.","Locate the param by searching your d.ts for `=` inside parameter lists of declare function/interface/constructor signatures and remove those defaults.","Wrap the translate call in try/catch per-file and skip/report files that use unsupported parameter forms.","File an issue on flowlint/flow repo with the repro d.ts so the param type gets an explicit unsupportedFeature recovery path instead of a raw throw."],"exampleFix":"// before (input .d.ts)\ndeclare function connect(endpoint: string, retries = 3): void;\n\n// after\nndeclare function connect(endpoint: string, retries?: number): void;","handlingStrategy":"try-catch","validationCode":"// Pre-scan d.ts source for default-initialized params before translating\nfunction hasUnsupportedFnParams(tsSource) {\n  // AssignmentPattern = '=' default value inside a declare signature's param list\n  return /(?:function\\s+\\w+|interface\\s+\\w+[\\s\\S]*?)[<(][^()=]*=\\s*[^,)>]/.test(tsSource);\n}","typeGuard":"const SUPPORTED_PARAMS = new Set(['Identifier', 'ArrayPattern', 'ObjectPattern', 'RestElement']);\nfunction paramsAreSupported(fnLikeNode) {\n  return fnLikeNode.params.every((p) => SUPPORTED_PARAMS.has(p.type));\n}","tryCatchPattern":"try {\n  const result = await unstable_translateTSDefToFlowDef({code: dts, recoverFromErrors: true});\n} catch (e) {\n  if (/^Unexpected function parameter/.test(e.message)) {\n    reportFile(file, 'unsupported param form (default value / parameter property) — rewrite as optional param');\n    continue; // skip file, keep batch running\n  }\n  throw e;\n}","preventionTips":["Keep .d.ts inputs free of default values in declaration parameters; use optional markers instead.","Run translation in per-file try/catch in batch tools so one bad declaration does not abort the run.","Pass recoverFromErrors: true so recoverable constructs degrade to comments rather than throws."],"tags":["typescript","flow","api-translator","unsupported-syntax","ast"],"backgroundTag":"unsupported-syntax","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}