microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.29k stars 12.39k forks source link

TSDoc @returns {@link foo} fails #50730

Open Tanimodori opened 2 years ago

Tanimodori commented 2 years ago

Type: Bug

In a workspace with TypeScript installed, open a new foo.d.ts, enter these following code

/**
 * @returns {@link foo} bar
 * @returns {@link foo | baz} bar
 * @returns z{@link foo} bar
 */
export function foo(): string;

The first and second @returns breaks while the third is correct. It seems the @returns has captured the { part from @link. This doc behaves correctly on TSDoc Playground.

VS Code version: Code 1.71.0 (784b0177c56c607789f9638da7b6bf3230d47a8c, 2022-09-01T07:36:10.600Z) OS version: Windows_NT x64 10.0.19044 Modes: Sandboxed: No

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 7 5700G with Radeon Graphics (16 x 3793)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|undefined| |Memory (System)|31.37GB (18.70GB free)| |Process Argv|C:\\Tanimodori\\Code\\@MJ\\majiang-core-test --crash-reporter-id 955eead6-045d-406b-92e1-7ed24cb4fcee| |Screen Reader|no| |VM|0%|
Extensions (44) Extension|Author (truncated)|Version ---|---|--- json-tree-view|Cha|2.6.0 npm-intellisense|chr|1.4.2 path-intellisense|chr|2.8.1 vscode-svgviewer|css|2.0.0 vscode-markdownlint|Dav|0.48.1 vscode-eslint|dba|2.2.6 gitlens|eam|12.2.2 prettier-vscode|esb|9.8.0 vscode-pull-request-github|Git|0.50.0 mdmath|goe|2.7.4 go|gol|0.35.2 gc-excelviewer|Gra|4.2.55 vue-snippets|hol|1.0.4 latex-workshop|Jam|8.29.0 MagicPython|mag|1.1.0 git-graph|mhu|1.30.0 dotenv|mik|1.0.1 vscode-language-pack-zh-hans|MS-|1.71.9070915 python|ms-|2022.14.0 remote-containers|ms-|0.251.0 remote-ssh|ms-|0.84.0 remote-ssh-edit|ms-|0.80.0 cmake-tools|ms-|1.12.26 cpptools|ms-|1.12.4 cpptools-extension-pack|ms-|1.3.0 vsliveshare|ms-|1.0.5711 vsliveshare-audio|ms-|0.1.91 vuejs-extension-pack|mub|1.9.0 gi|rub|0.2.11 vue-vscode-snippets|sdr|3.1.1 markdown-preview-enhanced|shd|0.6.3 shader|sle|1.1.5 vscode-status-bar-format-toggle|tom|3.1.1 cmake|twx|0.0.17 vscode-choosealicense|ult|0.8.0 vscodeintellicode|Vis|1.2.25 windicss-intellisense|voo|0.21.6 vscode-icons|vsc|11.16.0 volar|Vue|0.40.13 vscode-typescript-vue-plugin|Vue|0.40.13 JavaScriptSnippets|xab|1.8.0 clang-format|xav|1.9.0 markdown-all-in-one|yzh|3.4.3 minecraft-lang-colorizer|zz5|1.0.0 (2 theme extensions excluded)
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30557514 vsaa593:30376534 pythonvs932:30410667 cppdebug:30492333 pylanb8912:30545647 vsclangdc:30486549 c4g48928:30535728 hb751961:30553087 dsvsc012:30540252 azure-dev_surveyone:30548225 i497e931:30553904 ```

Code_8vTtRBiIo4 chrome_gsLGgjVaW4

Tanimodori commented 2 years ago

Also nested member in @link does not work, which is valid according to TSDoc docs and works in playground.

interface Foo {
  bar: Bar;
}

interface Bar {
  baz: number;
}

/**
 * {@link Foo.bar}
 * {@link Foo.bar.baz}
 * {@link Bar.baz}
 */
function foo();

Code_GhADsa31ub

Tanimodori commented 2 years ago

The @typeParam is also broken, while the @template works (see https://github.com/microsoft/tsdoc/issues/72#issuecomment-567290255)

sandersn commented 1 year ago

@Tanimodori please file separate bugs for your two followup comments.

sandersn commented 1 year ago

The expected syntax of @return is @return {typename} comment. @return {@link x} is ambiguous because {@link isn't a type, it's the beginning of the comment. The parser would require some lookahead to realise that it's not looking at a type expression but an @link.