-
Notifications
You must be signed in to change notification settings - Fork 12.8k
factory.createSourceFile doesn't accept JSDoc node (typings issue) #44151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This might happen to work today, but it's not the API contract. You need to attach the JS Doc comment to an |
Awesome didn't know that, thanks! |
I started experimenting with this again, and it seems like there's no way to attach |
@rbuckton any advice? |
The The only way you can have a transformer attach a "jsdoc" comment would be to use TypeScript/src/services/refactors/convertOverloadListToSingleSignature.ts Lines 156 to 165 in aa67b16
One option is to use the const printer = ts.createPrinter();
const output = printer.printNode(jsDoc).trim().replace(/^\/\*|\*\/$/, "");
addSyntheticLeadingComment(node, SyntaxKind.MultiLineCommentTrivia, output, /*hasTrailingNewLine*/ true); This will have obvious caveats, since it would be difficult to make indentation match. I could possibly see us modifying the synthetic comment functions to accept a |
Great explanation, thank you! The printer API trick seems like a good solution, as I format the output anyways with prettier, so should be ok to have indentation issues. |
But accepting JSDoc as leading/trailing comments would be amazing for codegen! |
I'm building an AST tree with factory API and printing it, there is no transformer involved. Is there any way I can attach comments on a synthesized node? |
Bug Report
π Search Terms
π Version & Regression Information
In v4.2.4 (current latest)
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Compiler error in
factory#createSourceFile
when aJSDoc[]
node supplied asStatement[]
is expected. If it's casted to any, its fine at runtime, so I assume it's just an issue with typings.π Expected behavior
Accept JSDoc as a root level element for
factory#createSourceFile
The text was updated successfully, but these errors were encountered: