When compiling declarations for the code snippet below using Typescript v5.0.4, I encounter an issue:
type SomeType<T> = {
field: T;
};
const getInstance = <T>(
value: T
): SomeType<{
[K in keyof T]: T[K];
}> => {
return {
field: value,
};
};
export const variable = getInstance({
/**
* want to have it in d.ts
*/
nested: "nested",
});
In the generated d.ts
file, the output is as follows:
type SomeType<T> = {
field: T;
};
export declare const variable: SomeType<{
nested: string;
}>;
export {};
The issue lies in the lack of preservation of comments in the generated declaration file when using mapped types. This problem does not arise if mapped types are not utilized.
Is there a way to retain comments in the d.ts
file when using mapped types? Interestingly, the comment is visible in VSCode when hovering over variable.field.nested
, indicating that Typescript retains it internally but fails to include it in the declaration generation process.