Title: Generating typescript definitions from JSDOC marked javascript fails · Issue #41250 · microsoft/TypeScript · GitHub
Open Graph Title: Generating typescript definitions from JSDOC marked javascript fails · Issue #41250 · microsoft/TypeScript
X Title: Generating typescript definitions from JSDOC marked javascript fails · Issue #41250 · microsoft/TypeScript
Description: TypeScript Version: tried both with 4.0.x and 4.1.0-dev.20201026 Search Terms: jsdoc generate javascript definitions Code The goal here is to create a index.d.ts for a library from a JSDoc documented javascript library, the problem is th...
Open Graph Description: TypeScript Version: tried both with 4.0.x and 4.1.0-dev.20201026 Search Terms: jsdoc generate javascript definitions Code The goal here is to create a index.d.ts for a library from a JSDoc document...
X Description: TypeScript Version: tried both with 4.0.x and 4.1.0-dev.20201026 Search Terms: jsdoc generate javascript definitions Code The goal here is to create a index.d.ts for a library from a JSDoc document...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/41250
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generating typescript definitions from JSDOC marked javascript fails","articleBody":"**TypeScript Version:** tried both with 4.0.x and 4.1.0-dev.20201026\r\n\r\n**Search Terms:** jsdoc generate javascript definitions\r\n\r\n**Code**\r\n\r\nThe goal here is to create a index.d.ts for a library from a JSDoc documented javascript library, the problem is that if the type of an object specified in a file, in this case *rectangle.js*, is \"declared\" as parameter or return type in another one:\r\n\r\n```\r\n/**\r\n * Adds a rectangle\r\n * \r\n * @returns {Rectangle} the rect\r\n */\r\n addRectangle() { /* ... */ }\r\n```\r\n\r\n... then an error is emitted since typescript tries to import it again as private symbol (at least this is my interpretation), a workaround pointed in another similar bug (closed) is to replace all the declarations of objects inside the JSDOC markup with something like:\r\n\r\n```\r\n/**\r\n * Adds a rectangle\r\n * \r\n * @returns {import('./rectangle').Rectangle} the rect\r\n */\r\n addRectangle() { /* ... */ }\r\n```\r\n\r\n.... this works, but totally destroy the JSDoc markup of the library.\r\n\r\nSimple repo that reproduces the problem (we need 3 files to reproduce it so I thought to keep it external):\r\n\r\nhttps://github.com/ggreco/doc2dec\r\n\r\n - checkout the repo\r\n - npm install\r\n - npm run build (or npx tsc)\r\n\r\n**Expected behavior:**\r\n\r\nI expect the types to be generated correctly in \"types\" (index.d.ts and rectangle.d.ts).\r\n\r\n**Actual behavior:**\r\n\r\nThe compilation fails with this error:\r\n`error TS9006: Declaration emit for this file requires using private name 'Rectangle' from module '\"/Users/gabry/projects/ts-test/rectangle\"'. An explicit type annotation may unblock declaration emit.`\r\n\r\nindex.d.ts is not generated.\r\n\r\n**Related Issues:** \r\nhttps://github.com/microsoft/TypeScript/issues/37832 (closed but not for this particular case)\r\n\r\n\r\n","author":{"url":"https://github.com/ggreco","@type":"Person","name":"ggreco"},"datePublished":"2020-10-26T16:57:44Z","url":"https://github.com/microsoft/TypeScript/issues/41250"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fa8e0f81-9421-6eed-393b-7aeedc30845e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E796:2C4BED:2DE29A7:3A4CBC2:6B01BB93 |
| html-safe-nonce | 60a6e8184b97d90451ed2319e0bdc82af1ce4a9d6156c944d0a402edef5c6b48 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzk2OjJDNEJFRDoyREUyOUE3OjNBNENCQzI6NkIwMUJCOTMiLCJ2aXNpdG9yX2lkIjoiMzQ5ODE3ODEyNDgyMTE1MDYxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 085d4beabef8215e9914ea2ecc7dea35d193a75f52b7a10a9509fee8ade8040f |
| hovercard-subject-tag | issue:729739471 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/41250/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad109a07f74fda9a55c0105545f9efbdd5ed9b466c64744f96b6135e9cede3ea/microsoft/TypeScript/issues/41250 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad109a07f74fda9a55c0105545f9efbdd5ed9b466c64744f96b6135e9cede3ea/microsoft/TypeScript/issues/41250 |
| og:image:alt | TypeScript Version: tried both with 4.0.x and 4.1.0-dev.20201026 Search Terms: jsdoc generate javascript definitions Code The goal here is to create a index.d.ts for a library from a JSDoc document... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ggreco |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width