-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
🔎 Search Terms
regression declaration file .d.ts imports relative absolute projects project-based build 4.3 4.3.x
🕗 Version & Regression Information
- This changed between versions 4.2.4 and 4.3.2
- Issue remains reproducible in the latest
nextbuild, currently 4.4.0-dev.20210602
⏯ Playground Link
Here is a repo with a minimal scenario (5 TS files + tsconfig.json):
https://github.com/ronjouch/ts43-import-regression
Just clone it and run npm run repro (after verifying what the script does)
💻 Code
This bug seems to be about projects, imports/exports through multiple files, so it gets confusing when having to list the multiple files here in a linear issue. Please check the repo.
Or see https://github.com/ronjouch/ts43-import-regression/commit/f55df20fc7cacd946cd3cd2ad5f99a08d7606290
🙁 Actual behavior
TS 4.3 writes .d.ts files that contain import statements referencing the local absolute project folder name (src-types in my example), which is meaningless and will cause dependents of the library to break.
See the second & third section of npm run repro (a helper script that builds under 4.2 & 4.3, and greps the culprit output):
===== Now with TS 4.3: the relative import will no longer be relative but absolute using the
===== project folder name, causing the library to break when used in another context
+ typescript@4.3.2
updated 1 package in 0.688s
> ts43-import-regression@1.0.0 compile /home/ronanj/ts43-import-regression
> tsc --build src-types src-dogs
protected static getDogConfig: () => import("src-types").DogConfig;
HERE: bad, absolute import ^^^^^^^^^^^
===== And lets see if it is fixed in the last nightly...
+ typescript@4.4.0-dev.20210602
updated 1 package in 0.662s
> ts43-import-regression@1.0.0 compile /home/ronanj/ts43-import-regression
> tsc --build src-types src-dogs
protected static getDogConfig: () => import("src-types").DogConfig;
🙂 Expected behavior
TS should resolve types in .d.ts using relative imports.
This is what happens with TS 4.2.4, see the first section of npm run repro:
+ typescript@4.2.4
updated 1 package in 0.687s
> ts43-import-regression@1.0.0 compile /home/ronanj/ts43-import-regression
> tsc --build src-types src-dogs
protected static getDogConfig: () => import("..").DogConfig;
HERE: good, a relative import ^^^^
===== Notice above how the type of getDogConfig type was compiled to a proper *relative* import,
===== through index.ts itself referencing something relative. Good.