In an Angular project, when I try to import things like Observable, or in this case, the switchMap operator, I have two options:
import { switchMap } from 'rxjs/operators';
or
import { switchMap } from 'rxjs/internal/operators';
What's the difference?
There is no difference.
import { switchMap } from 'rxjs/operators';
Is also loaded from the internal location, see operators/index.ts
I would suggest using the first one, if the rxjs maintainers change the internal project structure, it won't break your imports.
As of RxJS v7.2.0 it's adviced to import directly from 'rxjs':
import { switchMap } from 'rxjs';
As mentioned on the RxJS website:
With RxJS v7.2.0, most operators have been moved to 'rxjs' export site. This means that the preferred way to import operators is from 'rxjs', while 'rxjs/operators' export site has been deprecated.
Although the old way of importing operators is still active, it will be removed in one of the next major versions.