Title: foo.ts is resolved before foo.d.ts even if the latter is in files[] · Issue #22208 · microsoft/TypeScript · GitHub
Open Graph Title: foo.ts is resolved before foo.d.ts even if the latter is in files[] · Issue #22208 · microsoft/TypeScript
X Title: foo.ts is resolved before foo.d.ts even if the latter is in files[] · Issue #22208 · microsoft/TypeScript
Description: Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel. Imagine this simple app src/lib.ts export const a = 1; src/main.ts import {a} from './lib'; Imagine lib.ts was compiled se...
Open Graph Description: Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel. Imagine this simple app src/lib.ts export const a = 1; src/main.ts import {a} from...
X Description: Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel. Imagine this simple app src/lib.ts export const a = 1; src/main.ts import {a} from...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22208
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"foo.ts is resolved before foo.d.ts even if the latter is in files[]","articleBody":"Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel.\r\n\r\nImagine this simple app\r\n\r\n`src/lib.ts`\r\n```\r\nexport const a = 1;\r\n```\r\n`src/main.ts`\r\n```\r\nimport {a} from './lib';\r\n```\r\n\r\nImagine `lib.ts` was compiled separately, so there already exists\r\n`dist/lib.d.ts`\r\n```\r\nexport declare const a = 1;\r\n```\r\n\r\nNow, I want to compile `main.ts` as a separate program. Given `src/tsconfig.json`\r\n\r\n```\r\n{\r\n \"compilerOptions\": {\r\n \"rootDirs\": [\r\n \".\",\r\n \"../dist\"\r\n ],\r\n \"outDir\": \"../dist\",\r\n \"declaration\": true\r\n },\r\n\r\n \"files\": [\r\n \"main.ts\",\r\n // lib was compiled separately\r\n \"../dist/lib.d.ts\"\r\n ]\r\n}\r\n```\r\n\r\nWe see that `lib.d.ts` is already in the program before resolution begins. However the compiler resolves the import statement to the `lib.ts` file instead, adding it to the program, and tries to emit on top of an input, so the error is\r\n\r\n```\r\n$ ./node_modules/.bin/tsc -p src\r\nerror TS5055: Cannot write file '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/dist/lib.d.ts' because it would overwrite input file.\r\n```\r\n\r\nOkay, we didn't want `lib.ts` in the program, so we should just use `--noResolve` to prevent that, but it's also broken:\r\n```\r\n$ ./node_modules/.bin/tsc -p src --noResolve --traceResolution\r\n======== Resolving module './lib' from '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/main.ts'. ========\r\nModule resolution kind is not specified, using 'NodeJs'.\r\n'rootDirs' option is set, using it to resolve relative module name './lib'.\r\nChecking if '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/' is the longest matching prefix for '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib' - 'true'.\r\nChecking if '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/dist/' is the longest matching prefix for '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib' - 'false'.\r\nLongest matching prefix for '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib' is '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/'.\r\nLoading 'lib' from the root dir '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/', candidate location '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib'.\r\nLoading module as file / folder, candidate module location '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib', target file type 'TypeScript'.\r\nFile '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib.ts' exist - use it as a name resolution result.\r\n======== Module name './lib' was successfully resolved to '/usr/local/google/home/alexeagle/Projects/repro_ts_resolving_ts/src/lib.ts'. ========\r\nsrc/main.ts(1,17): error TS2307: Cannot find module './lib'.\r\n```\r\n\r\nSo far our workaround at Google is one of:\r\n- use Bazel sandboxing to make the inputs appear in different places\r\n- use our own custom compiler which elides any emit to files we don't expect\r\n\r\nHowever under Bazel we sometimes cannot sandbox (eg. on Windows) and cannot use our custom compiler (eg. when we are compiling it)\r\nso we are stuck.\r\n\r\nI found that `ts.CompilerOptions.suppressOutputPathCheck` could be a workaround, but `tsc` doesn't allow that flag from the command line or tsconfig.json (it's not in `optionDeclarations` in `commandLineParser.ts`)","author":{"url":"https://github.com/alexeagle","@type":"Person","name":"alexeagle"},"datePublished":"2018-02-27T19:37:45Z","url":"https://github.com/microsoft/TypeScript/issues/22208"}
| 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:93d9a196-57c9-135f-7301-f748548c9a33 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C50:26981B:21588F:2DE98A:6B0451C3 |
| html-safe-nonce | d4bde6807c838211c0529870a267cade2c7d05bf1a586e8bf2a06ac91ea85888 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzUwOjI2OTgxQjoyMTU4OEY6MkRFOThBOjZCMDQ1MUMzIiwidmlzaXRvcl9pZCI6IjgxMjE2OTM1ODE2NzI2NTczMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6f265c030fe2788ead89a9d88ed1771b5910f14fca63e298465ece744a11b630 |
| hovercard-subject-tag | issue:300764867 |
| 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/22208/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a0dc9536c2cdd5c0e62820d5b9a8827aa826d3afe7bd51817ed5f4f3f1beac7/microsoft/TypeScript/issues/22208 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a0dc9536c2cdd5c0e62820d5b9a8827aa826d3afe7bd51817ed5f4f3f1beac7/microsoft/TypeScript/issues/22208 |
| og:image:alt | Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel. Imagine this simple app src/lib.ts export const a = 1; src/main.ts import {a} from... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexeagle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0 |
| 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 | e086f9b7e88322eb2b41885a6ad425b215737fa5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width