The problem is clearly visible in the image below, as it pertains to the popup box in VSCode displaying type information and comments. https://i.sstatic.net/rncRy.png
Although the code works fine in VSCode, TypeScript Playground fails to display the comments properly, so it's best to avoid using it.
This issue is not limited to regular comments; it also affects comments within template literal types.
/**
* A special string with documentation for reuse.
*/
type SpecialString = string;
interface Options {
/** Foo */
x: number;
/** Bar */
y: number;
s: SpecialString;
}
const fn1 = (options: Options) => {
console.log('foo');
};
/*
Expected behavior is to see comments in the popup when passing 'x' and 'y', but the comment is missing for 's'.
*/
// fn1({})
// Repeating the same comment for both fn2 and fn3 is not ideal
const fn2 = (special: SpecialString) => console.log(special);
const fn3 = (special: SpecialString, x: number) => console.log('foo');
/*
The 'Special' comment does not appear when passing the argument unless it is copied into an @param annotation for both fn2 and fn3.
*/
// fn2();
interface SpecialStrings {
/** Comment for SpecialStrings property */
special: string;
}
const fn4 = (special: SpecialStrings['special']) => console.log(special);
/*
Even this approach fails to display the comment when passing the argument.
*/
// fn4();