(typeNode, options)
| 362 | |
| 363 | // Convert JSDoc FunctionType into a TypeScript function signature string |
| 364 | function convertFunctionTypeForInterface(typeNode, options) { |
| 365 | const params = (typeNode.params || []) |
| 366 | .map((param, i) => { |
| 367 | let typeObj; |
| 368 | let paramName; |
| 369 | if (param.type === 'ParameterType') { |
| 370 | typeObj = param.expression; |
| 371 | paramName = param.name ?? `p${i}`; |
| 372 | } else if (typeof param.type === 'object' && param.type !== null) { |
| 373 | typeObj = param.type; |
| 374 | paramName = param.name ?? `p${i}`; |
| 375 | } else { |
| 376 | // param itself is a plain type node |
| 377 | typeObj = param; |
| 378 | paramName = `p${i}`; |
| 379 | } |
| 380 | const paramType = convertTypeToTypeScript(typeObj, options); |
| 381 | return `${paramName}: ${paramType}`; |
| 382 | }) |
| 383 | .join(', '); |
| 384 | |
| 385 | const returnType = typeNode.result |
| 386 | ? convertTypeToTypeScript(typeNode.result, options) |
| 387 | : 'void'; |
| 388 | |
| 389 | // Normalise 'undefined' return to 'void' for idiomatic TypeScript |
| 390 | const normalisedReturn = returnType === 'undefined' ? 'void' : returnType; |
| 391 | |
| 392 | return `(${params}) => ${normalisedReturn}`; |
| 393 | } |
| 394 | |
| 395 | // Generate a TypeScript interface from a typedef with @property fields |
| 396 | function generateTypedefInterface(name, typedefEntry, options = {}, indent = 2) { |
no test coverage detected