Repository: TypeScript
Issue: tsc build declarationMap generates incorrect mappings from JSDoc
Labels: Bug,Help Wanted

# Bug Report

### 🔎 Search Terms

declarationMap (declaration map) incorrect mappings JSDoc 

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries 

```
$ npx typescript@next --version
Version 4.7.0-dev.20220302
```

### ⏯ Playground Link

[SourceMap visualizer with relevant code](https://sokra.github.io/source-map-visualization/#base64,ZXhwb3J0IGZ1bmN0aW9uIFJlbW90YWJsZShpZmFjZT86IHN0cmluZyB8IHVuZGVmaW5lZCwgcHJvcHM/OiB1bmRlZmluZWQsIHJlbW90YWJsZT86IGFueSk6IGFueTsKZXhwb3J0IGZ1bmN0aW9uIEZhcjxUPihmYXJOYW1lOiBzdHJpbmcsIHJlbW90YWJsZT86IFQgfCB1bmRlZmluZWQpOiBUOwpleHBvcnQgZnVuY3Rpb24gVG9GYXJGdW5jdGlvbihmYXJOYW1lOiBzdHJpbmcsIGZ1bmM6ICguLi5hcmdzOiBhbnlbXSkgPT4gYW55KTogKC4uLmFyZ3M6IGFueVtdKSA9PiBhbnk7CmV4cG9ydCB0eXBlIEludGVyZmFjZVNwZWMgPSBpbXBvcnQoJy4vdHlwZXMuanMnKS5JbnRlcmZhY2VTcGVjOwovLyMgc291cmNlTWFwcGluZ1VSTD1tYWtlLWZhci5kLnRzLm1hcA==,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFrZS1mYXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1ha2UtZmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXVGTyw4REFMSSxTQUFTLGNBRVQsR0FBRyxHQUNELEdBQUcsQ0E4Q2Y7QUFZTSxnQ0FMSSxNQUFNLGdDQVFoQjtBQWVNLHVDQUpJLE1BQU0sa0JBRUksR0FBRyxFQUFFLEtBQUssR0FBRyxhQUFiLEdBQUcsRUFBRSxLQUFLLEdBQUcsQ0FPakM7NEJ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poYXJkZW4oVG9GYXJGdW5jdGlvbik7Cg==)

### 💻 Code

[Source code sample used in visualizer](https://github.com/endojs/endo/blob/%40endo/marshal%400.6.2/packages/marshal/src/make-far.js)

### 🙁 Actual behavior

Go To Definition in VS Code is off by some line / columns. Source mapping visualizer seem to show that generated map is not accurate.

### 🙂 Expected behavior

Correct source mapping for all type definitions, including function parameters and their types.