(signature: string)
| 337 | // e.g. `Options<T> & QueryKeyWithDataTag<T>` becomes the members of `Options` followed by the tag. |
| 338 | const sourceFiles = new Map<string, ts.SourceFile>() |
| 339 | async function declaredSignatureTypes(signature: string) { |
| 340 | const location = signature.match(/^Defined in: \[([^\]]+):(\d+)\]/m) |
| 341 | if (!location) { |
| 342 | return undefined |
| 343 | } |
| 344 | const [, file, line] = location |
| 345 | let source = sourceFiles.get(file!) |
| 346 | if (!source) { |
| 347 | const text = await readFile(resolve(__dirname, '..', file!), 'utf8').catch( |
| 348 | () => undefined, |
| 349 | ) |
| 350 | if (text === undefined) { |
| 351 | return undefined |
| 352 | } |
| 353 | source = ts.createSourceFile(file!, text, ts.ScriptTarget.Latest, true) |
| 354 | sourceFiles.set(file!, source) |
| 355 | } |
| 356 | let found: ts.SignatureDeclaration | undefined |
| 357 | const visit = (node: ts.Node) => { |
| 358 | if (found) { |
| 359 | return |
| 360 | } |
| 361 | if ( |
| 362 | ts.isFunctionLike(node) && |
| 363 | 'parameters' in node && |
| 364 | source.getLineAndCharacterOfPosition(node.getStart()).line === |
| 365 | Number(line) - 1 |
| 366 | ) { |
| 367 | found = node |
| 368 | return |
| 369 | } |
| 370 | ts.forEachChild(node, visit) |
| 371 | } |
| 372 | visit(source) |
| 373 | return found && { parameter: found.parameters[0]?.type, returns: found.type } |
| 374 | } |
| 375 | |
| 376 | // Types that only transform their first type argument, so a label keeps that argument to stay |
| 377 | // meaningful, e.g. `Omit<UseMutationOptions>` instead of `Omit`. |
no test coverage detected