Title: Module resolution via "--paths" fails against declaration files generated alongside "--outfile:" · Issue #18311 · microsoft/TypeScript · GitHub
Open Graph Title: Module resolution via "--paths" fails against declaration files generated alongside "--outfile:" · Issue #18311 · microsoft/TypeScript
X Title: Module resolution via "--paths" fails against declaration files generated alongside "--outfile:" · Issue #18311 · microsoft/TypeScript
Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Code /bundles - app.js - app.d.ts - common.js - common.d.ts - core.js - core.d.ts /app - main.ts - tsconfig.ts /src/common - index.ts - file1.ts - tsconfig.json /src/core - i...
Open Graph Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Code /bundles - app.js - app.d.ts - common.js - common.d.ts - core.js - core.d.ts /app - main.ts - tsconfig.ts /src/common - index.ts ...
X Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Code /bundles - app.js - app.d.ts - common.js - common.d.ts - core.js - core.d.ts /app - main.ts - tsconfig.ts /src/common - index.ts ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/18311
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Module resolution via \"--paths\" fails against declaration files generated alongside \"--outfile:\"","articleBody":"**TypeScript Version:** 2.4.0 / nightly (2.5.0-dev.201xxxxx)\r\n2.5.2\r\n**Code**\r\n\r\n```\r\n/bundles\r\n- app.js\r\n- app.d.ts\r\n- common.js\r\n- common.d.ts\r\n- core.js\r\n- core.d.ts\r\n\r\n/app\r\n- main.ts\r\n- tsconfig.ts\r\n\r\n/src/common\r\n- index.ts\r\n- file1.ts\r\n- tsconfig.json\r\n\r\n/src/core\r\n- index.ts\r\n- file1.ts\r\n- tsconfig.json\r\n\r\n//app/main.ts\r\nimport { resource } from '@bundles/core'\r\nimport { somethingElse } from '@bundles/common'\r\n\r\n//common/index.ts\r\nexport * from './file1.ts'\r\n\r\n//core/index.ts\r\nexport * from './file1.ts'\r\n\r\n//app/tsconfig.json\r\n...\r\n\"target\": \"es5\",\r\n\"module\": \"system\",\r\n\"rootDir\": \".\",\r\n\"outFile\": \"../bundles/app.js\",\r\n\"declarations\": true,\r\n\"paths\": {\r\n \"@bundles/*\": [\"../bundles/*\"]\r\n}\r\n...\r\n\r\n//common/tsconfig.json\r\n...\r\n\"target\": \"es5\",\r\n\"module\": \"system\",\r\n\"rootDir\": \".\",\r\n\"outFile\": \"../bundles/common.js\",\r\n\"declarations\": true,\r\n\"paths\": {\r\n \"@bundles/*\": [\"../bundles/*\"]\r\n}\r\n...\r\n\r\n//core/tsconfig.json\r\n...\r\n\"target\": \"es5\",\r\n\"module\": \"system\",\r\n\"rootDir\": \".\",\r\n\"outFile\": \"../bundles/core.js\",\r\n\"declarations\": true\r\n\"paths\": {\r\n \"@bundles/*\": [\"../bundles/*\"]\r\n}\r\n\r\n// bundles/common.d.ts\r\ndeclare module \"index\" {\r\n export * from 'file1'\r\n}\r\n\r\n// bundles/core.d.ts\r\ndeclare module \"index\" {\r\n export * from 'file1'\r\n}\r\n...\r\n```\r\n\r\n\r\n\r\n**Expected behavior:**\r\nTSC to correctly resolve the import statements within `app/main.ts` against the configured `--paths`, applying the same logical resolution strategy that lets it resolve barrels.\r\n\r\n(note: I've had to escape the [@] symbols for some reason at the start of these lines).\r\n\r\n```\r\n\"[@]bundles/common\" => '../bundles/common.d.ts' => '../bundles/common.d.ts [declared module \"index\"]' (OK)\r\n\r\n\"[@]bundles/core\" => '../bundles/core.d.ts' => '../bundles/core.d.ts [declared module \"index\"]' (OK)\r\n\r\n\"[@]bundles/*\" => '../bundles/*.d.ts => \"[declared module *]\" => \"[declared module index]\" => \"../bundles/*/index.d.ts\" => \"[declared module *]\" => \"[declared module index]\"\r\n```\r\n \r\n**Actual behavior:**\r\n\r\nIt appears the path part of the import statement is currently expected to be included in the declared module name.\r\n\r\n```\r\n\"[@]bundles/common\" => '../bundles/common.d.ts' => '../bundles/common.d.ts [declared module \"@bundles/common\"]' (FAIL)\r\n```\r\n\r\nEven if I name` index.ts` to `common.ts` for example, this will still fail because the resolution logic is expecting the `\"@bundles\"` path token to be in the declared module name. \r\n\r\nI can coerce the expected behavior by creating a \"@bundles\" folder inside my module - but the whole point is that the \"--paths\" option shouldn't be married to the module structure. \r\n\r\n```\r\n/src/common\r\n- @bundles/\r\n-- common.ts\r\n\r\n//src/common/@bundles/common.ts\r\nexport * from '../index'\r\n\r\n//bundles/common.d.ts\r\ndeclare module \"index\" {\r\n exports \"file1\r\n}\r\n\r\ndeclare module \"@bundles/common\" {\r\n exports \"index\"\r\n}\r\n```","author":{"url":"https://github.com/josh-sachs","@type":"Person","name":"josh-sachs"},"datePublished":"2017-09-07T14:49:47Z","url":"https://github.com/microsoft/TypeScript/issues/18311"}
| 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:3c138bd2-dd9c-37a1-0a46-d93f18d36465 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9432:2D2F2F:CE25B9:10B02B7:6B00F191 |
| html-safe-nonce | 188b6d612176bf666aa0eaf75cfaffa302b32058d093785a3280cd2139061752 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDMyOjJEMkYyRjpDRTI1Qjk6MTBCMDJCNzo2QjAwRjE5MSIsInZpc2l0b3JfaWQiOiI2NzIwNjYyMDE3OTQzODU5NjAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7310db05b928a45074aa4eb1b5abb76a93941753858199b55520c99ead0771d2 |
| hovercard-subject-tag | issue:255963917 |
| 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/18311/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f5bbdfb3b1b27a2e94163a9263e327ece058f0414bb13ed43be3093ba876f1c/microsoft/TypeScript/issues/18311 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f5bbdfb3b1b27a2e94163a9263e327ece058f0414bb13ed43be3093ba876f1c/microsoft/TypeScript/issues/18311 |
| og:image:alt | TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Code /bundles - app.js - app.d.ts - common.js - common.d.ts - core.js - core.d.ts /app - main.ts - tsconfig.ts /src/common - index.ts ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | josh-sachs |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width