Title: With project references, some cross-package imports of inferred types are emitted with relative paths · Issue #39117 · microsoft/TypeScript · GitHub
Open Graph Title: With project references, some cross-package imports of inferred types are emitted with relative paths · Issue #39117 · microsoft/TypeScript
X Title: With project references, some cross-package imports of inferred types are emitted with relative paths · Issue #39117 · microsoft/TypeScript
Description: TypeScript Version: 3.9.5 (also repros with nightly) Search Terms: project references, declaration files, tsconfig paths, inferred types Code The repro requires a monorepo with project references plus paths in the tsconfig. Full repro wi...
Open Graph Description: TypeScript Version: 3.9.5 (also repros with nightly) Search Terms: project references, declaration files, tsconfig paths, inferred types Code The repro requires a monorepo with project references p...
X Description: TypeScript Version: 3.9.5 (also repros with nightly) Search Terms: project references, declaration files, tsconfig paths, inferred types Code The repro requires a monorepo with project references p...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/39117
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"With project references, some cross-package imports of inferred types are emitted with relative paths","articleBody":"\u003c!-- 🚨 STOP 🚨 STOP 🚨 STOP 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** 3.9.5 (also repros with nightly)\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** project references, declaration files, tsconfig paths, inferred types\r\n\r\n**Code**\r\n\r\nThe repro requires a monorepo with project references plus `paths` in the tsconfig. Full repro with the problematic compiled output checked in here: https://github.com/ecraig12345/learn-a/tree/inferred-relative-imports (it's fairly minimal but may still include a few settings which turn out to be tangential to the issue, sorry)\r\n\r\nHere's a summary...\r\n\r\n`@fluentui/pkg2` depends on `@fluentui/pkg1`, and both live in the same monorepo under a `packages` folder.\r\n\r\n[`pkg2`'s tsconfig](https://github.com/ecraig12345/learn-a/blob/inferred-relative-imports/packages/pkg2/tsconfig.json) has a project reference pointing to `pkg1`, and both build with `composite: true`.\r\n\r\nThey inherit from a [shared tsconfig](https://github.com/ecraig12345/learn-a/blob/inferred-relative-imports/tsconfig.json) which has a path config like this (to allow imports directly from the root of each package):\r\n```\r\n\"baseUrl\": \".\",\r\n\"paths\": {\r\n \"@fluentui/*\": [\"packages/*/src\"]\r\n}\r\n```\r\n\r\nThe problem comes when you have a file in one package ([`pkg2/src/index.ts`](https://github.com/ecraig12345/learn-a/blob/inferred-relative-imports/packages/pkg2/src/index.ts) in the repro) which has an implicit/inferred reference to a type from another local project-referenced package. \r\n```ts\r\nimport { IThings } from '@fluentui/pkg1';\r\n\r\nexport function fn4() { // inferred return type: IThings from pkg1\r\n const a: IThings = { thing1: { a: 'b' } };\r\n return a.thing1;\r\n}\r\n```\r\nThis inferred type need not be stated locally, but it will show up in the declaration file as an inline `import()`.\r\n\r\n**Expected behavior:**\r\n\r\nCompile each package with `tsc` (or in the repro, run `yarn build` from the root).\r\n\r\n`pkg2`'s `index.d.ts` looks like this:\r\n```ts\r\nexport declare function fn4(): import(\"@fluentui/pkg1\").IThing;\r\n```\r\n\r\n**Actual behavior:**\r\n\r\n[`pkg2`'s `index.d.ts`](https://github.com/ecraig12345/learn-a/blob/inferred-relative-imports/packages/pkg2/lib/src/index.d.ts) looks like this, which will break consumers:\r\n```ts\r\nexport declare function fn4(): import(\"../../pkg1/src\").IThing;\r\n```\r\n\r\n`pkg2/src/index.ts` output also adds an `src` folder under `lib`, which I wouldn't expect (`pkg2/lib/src/index.{js,d.ts}`), but this is probably unrelated.\r\n\r\nVariants:\r\n- Same behavior if `-b` is added to the build command.\r\n- Same behavior if using `rootDir` instead of `include`, just different output directory structure.\r\n- Same behavior if the config inheritance is removed and `paths` config is moved to each project.\r\n- Without project references, you end up with a directory structure like this, which I also don't understand, but is not the same issue:\r\n```\r\npkg2/\r\n lib/\r\n pkg1/src/\u003cfiles>\r\n pkg2/src/\u003cfiles>\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> can't be shown on playground\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? --> didn't see anything else quite like this","author":{"url":"https://github.com/ecraig12345","@type":"Person","name":"ecraig12345"},"datePublished":"2020-06-17T18:18:59Z","url":"https://github.com/microsoft/TypeScript/issues/39117"}
| 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:1785e6b9-1406-23de-3827-24f4c96a30ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A6E4:785A9:2B26A35:36CD171:6B01AC6D |
| html-safe-nonce | 31bfc6b6b0b94c3407424817d5dbb01a31c8bc9476e579db4e287fab3c5a44f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkU0Ojc4NUE5OjJCMjZBMzU6MzZDRDE3MTo2QjAxQUM2RCIsInZpc2l0b3JfaWQiOiI1NTUzODc0NzQ4MjkyODM2NDYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 24789b673f5a6e9c05e2d1d95604c940cd77201f167ecefc085954370971a62a |
| hovercard-subject-tag | issue:640648018 |
| 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/39117/issue_layout |
| twitter:image | https://opengraph.githubassets.com/21f193566fc49fc478dfb705235cf320685cc309fd22def3bce81c9d7b8fc5ab/microsoft/TypeScript/issues/39117 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/21f193566fc49fc478dfb705235cf320685cc309fd22def3bce81c9d7b8fc5ab/microsoft/TypeScript/issues/39117 |
| og:image:alt | TypeScript Version: 3.9.5 (also repros with nightly) Search Terms: project references, declaration files, tsconfig paths, inferred types Code The repro requires a monorepo with project references p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ecraig12345 |
| 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