TypeScript: Auto imports not working properly with RxJS 7 beta
- VS Code Version: any
- OS Version: any
Steps to Reproduce:
- Add
rxjs@7.0.0-beta.12to a project - type
concatMapand check the possible auto-import locations - It should show
rxjs/operatorsas the correct import location. Instead it showsrxjs/dist/types/operators.
Does this issue occur when all extensions are disabled?: Yes
This comes from an issue reported on the RxJS repository here: https://github.com/ReactiveX/rxjs/issues/6067
Apparently, neovim users don’t experience this issue, so it leads me to believe it’s not the configuration of the package.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 35 (14 by maintainers)
Commits related to this issue
- chore: Add typesVersions to package.json This is an attempt to fix issues with VS Code auto-import, as described here in this issue: https://github.com/microsoft/TypeScript/issues/43034\#issuecomment... — committed to benlesh/rxjs by benlesh 3 years ago
- chore: Add typesVersions to package.json (#6229) This is an attempt to fix issues with VS Code auto-import, as described here in this issue: https://github.com/microsoft/TypeScript/issues/43034\#issu... — committed to ReactiveX/rxjs by benlesh 3 years ago
- fix: VS code will now properly import operators, et al - Adds typesVersions, enforcing TypeScript >= 4.2. - Adds some superfluous imports required for TS and VS Code to find proper import locations f... — committed to benlesh/rxjs by benlesh 3 years ago
- fix: VS code will now properly import operators, et al - Adds typesVersions, enforcing TypeScript >= 4.2. - Adds some superfluous references required for TS and VS Code to find proper import location... — committed to benlesh/rxjs by benlesh 3 years ago
- fix: VS code will now properly import operators, et al (#6276) - Adds typesVersions, enforcing TypeScript >= 4.2. - Adds some superfluous references required for TS and VS Code to find proper import... — committed to ReactiveX/rxjs by benlesh 3 years ago
- fix index.d.ts resolution. https://github.com/microsoft/TypeScript/issues/43034#issuecomment-823423227 — committed to tianwenh/utils by tianwenh 2 years ago
FWIW: I agree that the rxjs package is weird. It’s ALL weird. I hate module resolution and I’ll hate it until CJS dies or ESM gives up.
@benlesh you can use
instead of
import "./operators".There’s no guarantee it had to work out that way. The relative paths match up because it made sense to a human to do it that way, but I could fork RxJS and make a version that breaks that expectation.
There are lots of solutions, because you really have to be doing non-standard stuff to break this in the first place. In general, shipping types in a different subfolder (e.g.
dist/types) from the rest of the JS is a recipe for pain. By far the happiest path is just shipping the JS and .d.ts thattscgives you alongside each other. I’m sure there are lots of compelling Technical Reasons why RxJS is doing something different, but the farther you get from that happy path, the more you’re likely to subtly break editor features or have to pile on cascading workarounds to avoid breaking them.Yes, first you need to import something from
rxjs/operatorsin another file of the same project. This usually hints thatrxjs/operatorsalso has exports.The issue in the other files (where it hasn’t been manually imported), then VSCode suggests
rxjs/dist/types/operatorsinstead.My environment, btw:
Literally testing auto-imports functionality would be hard and out of scope, in my opinion. It should be trivial to test module resolution on a tiny TypeScript program with
tsc, though. And you could test the set of files visible to auto-imports by runningtsc --listFilesOnlyon an input file with contentimport 'rxjs'. (You could do the same with the compiler’s JS API, but shelling out and splitting STDOUT by line seems easier.)I wonder if it can be inferred in some way… The root’s RxJS@7 package.json has
When we use
Observableand try to get import suggestions, Observable is exported from within./dist/types/index.d.tsand we correctly receive to import from'rxjs'Now, if we use
mapand try to get import suggestions… why is TS Server looking atdist/types/operators/index.d.tsat the first place? Isn’t there a way where we can use this information together with./dist/types/index.d.tsto see that the relative path todist/types/operators/index.d.tsis./operators?In a way, this map feels like it should be simple:
Although I understand that it’s not as straightforward.
Otherwise is there any suggestion on how to change the structure to support these kind of imports?
This issue has been marked as ‘External’ and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Reproduced for me with TS 4.2.3.
Yes, There is no suggestions to import
concatMap(another bug, I think it is #30033), until there is no.tsfiles withrxjs/operatorsimport.After adding mentioned
.tsfile, for example:The bug appears:
OS Version:
Linux manjaro 5.4.97-1-MANJAROCode Version:
All extensions are disabled.
Having trouble getting any auto imports for
mapto show up:There are no auto imports:
Any extra steps required while setting up the project?