Skip to content

Declaration file has wrong reference path for composite projects #37928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timocov opened this issue Apr 13, 2020 · 2 comments · Fixed by #39645
Closed

Declaration file has wrong reference path for composite projects #37928

timocov opened this issue Apr 13, 2020 · 2 comments · Fixed by #39645
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@timocov
Copy link
Contributor

timocov commented Apr 13, 2020

TypeScript Version: 3.9.0-dev.20200413, 3.8.3

Search Terms: composite projects, declaration files, paths, reference, baseUrl

Code

  1. Download zip with the project ts-bug.zip
  2. npm install
  3. npm run build-non-composite - it should be fine

Then, if you run npm run build - there are 2 errors:

lib/src/common/nominal.d.ts:2:55 - error TS2304: Cannot find name 'MyNominal'.

2 export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;
                                                        ~~~~~~~~~

lib/src/common/nominal.d.ts:1:22 - error TS6053: File 'C:/projects/src/common/types.d.ts' not found.

1 /// <reference path="../../../src/common/types.d.ts" />
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And if you run npm run build-baseUrl - there are another 2 errors:

lib/src/common/nominal.d.ts:2:55 - error TS2304: Cannot find name 'MyNominal'.

2 export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;
                                                        ~~~~~~~~~

lib/src/common/nominal.d.ts:1:23 - error TS2688: Cannot find type definition file for 'types'.

1 /// <reference types="types" />
                        ~~~~~

This is pretty similar to #31696. In this case we have 2 bugs:

  1. For npm run build incorrect generated path for reference path (it exits for 1 more folder).
  2. For npm run build-baseUrl (which is differ from build case in the only baseUrl compiler option in common sub-project) incorrectly replaced refernce path with reference types, so no project could use it because they might (and will) not have the same baseUrl option.

Related Issues: #31696, #25600

@timocov
Copy link
Contributor Author

timocov commented Apr 13, 2020

I think that in both cases there should be reference path directive with correct path (without exceeded ..).

@sheetalkamat
Copy link
Member

npm run build is definitely bug and #39645 fixes that.

npm run build-baseUrl well that raises questions. #32878 started preferring types over reference paths to make it more portable. But our resolve type reference name doesnt use baseUrl so this is kind of questionable.
Other way to look at it would be when file is referenced throught only referece path from root file tree (or relative imports) prefer relative path instead of portable path.

sheetalkamat added a commit that referenced this issue Jul 17, 2020
….d.ts and not original source file) since they are rewritten in the .d.ts emit (#39645)

* Add tests corresponding to repro from #37928

* Triple slash references must resolve against the resolved file name (.d.ts and not original source file) since they are rewritten in the .d.ts emit

* Remove the scenario not fixed in this PR
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment