Title: Importing types from a js module doesn't work · Issue #28660 · microsoft/TypeScript · GitHub
Open Graph Title: Importing types from a js module doesn't work · Issue #28660 · microsoft/TypeScript
X Title: Importing types from a js module doesn't work · Issue #28660 · microsoft/TypeScript
Description: TypeScript Version: 3.2.0-rc Code Example from TypeScript 2.9 release notes: // module.js class Pet { get name() { return ""; } } module.exports = {Pet}; // global-script.ts // error TS2694: Namespace `"module".export=` has no exported m...
Open Graph Description: TypeScript Version: 3.2.0-rc Code Example from TypeScript 2.9 release notes: // module.js class Pet { get name() { return ""; } } module.exports = {Pet}; // global-script.ts // error TS2694: Namesp...
X Description: TypeScript Version: 3.2.0-rc Code Example from TypeScript 2.9 release notes: // module.js class Pet { get name() { return ""; } } module.exports = {Pet}; // global-script.ts // error TS26...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28660
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Importing types from a js module doesn't work","articleBody":"**TypeScript Version:** 3.2.0-rc\r\n\r\n**Code**\r\n\r\nExample from [TypeScript 2.9 release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types):\r\n\r\n```ts\r\n// module.js\r\n\r\nclass Pet {\r\n get name() {\r\n return \"\";\r\n }\r\n}\r\n\r\nmodule.exports = {Pet};\r\n```\r\n\r\n```ts\r\n// global-script.ts\r\n\r\n// error TS2694: Namespace `\"module\".export=` has no exported member `Pet`.\r\n\r\nfunction adopt(p: import(\"./module\").Pet) {\r\n console.log(`Adopting ${p.name}...`);\r\n}\r\n\r\n// This works, though it's far from ideal, and not always applicable.\r\n\r\nlet module: typeof import(\"./module\");\r\n\r\nfunction adopt2(p: typeof module.Pet.prototype) {\r\n console.log(`Adopting ${p.name}...`);\r\n}\r\n```\r\n\r\n```js\r\n// a.js\r\n\r\n// error TS2694: Namespace `\"module\".export=` has no exported member `Pet`.\r\n\r\n/**\r\n * @param {import(\"./module\").Pet} p\r\n */\r\nfunction walk(p) {\r\n console.log(`Walking ${p.name}...`);\r\n}\r\n\r\n// Works, showing that type information is exported/preserved on some level.\r\n\r\n/**\r\n * @typedef {import(\"./module\")} module\r\n * @param {typeof module.Pet.prototype} p\r\n */\r\nfunction walk2(p) {\r\n console.log(`Walking ${p.name}...`);\r\n}\r\n```\r\n\r\nTypecheck using:\r\n\r\n```\r\ntsc -t es2017 --checkjs --allowjs --noemit a.js global-script.ts\r\n```\r\n\r\n**Expected behavior:**\r\nType annotation should work and not error out.\r\n\r\n**Actual behavior:**\r\nerror TS2694: Namespace `\"module\".export=` has no exported member `Pet`.\r\n\r\n**Related Issues:**\r\nIssue #23936 seems possibly related, but not sure.","author":{"url":"https://github.com/zombie","@type":"Person","name":"zombie"},"datePublished":"2018-11-23T22:20:11Z","url":"https://github.com/microsoft/TypeScript/issues/28660"}
| 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:d2eb8ae9-2303-5ebf-53fc-a8b4f737cbd0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D2F2:11EACE:2999E06:379548E:6B01BB7D |
| html-safe-nonce | a578a57787cfef64af986e4d5d95a3dba7f4fd190401e692b9e64f8a79881d4a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkYyOjExRUFDRToyOTk5RTA2OjM3OTU0OEU6NkIwMUJCN0QiLCJ2aXNpdG9yX2lkIjoiNzMyMzkzNDcwNDg4ODAzNjIyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3357d2dfbc62e4cdfa135cf807ef20c60215d877631e7c69f971dae6eca68fb8 |
| hovercard-subject-tag | issue:383935254 |
| 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/28660/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ce3024654ce12294bf0e4d6858eed2e022141de18f4fc3c1f0f0d11841be82cd/microsoft/TypeScript/issues/28660 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ce3024654ce12294bf0e4d6858eed2e022141de18f4fc3c1f0f0d11841be82cd/microsoft/TypeScript/issues/28660 |
| og:image:alt | TypeScript Version: 3.2.0-rc Code Example from TypeScript 2.9 release notes: // module.js class Pet { get name() { return ""; } } module.exports = {Pet}; // global-script.ts // error TS2694: Namesp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zombie |
| 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