I m curious why deep imp…

1 minute read

I’m curious why deep imports are a bad practice?


you want to be able to have code that is private to a particular lib and won’t be used by code in other parts of the monorepo

that way you know that you are explicitly providing an api for your lib code by exporting from index.ts

if someone depends on a particular function in your lib, this forces you to never change that code or you’ll break their app

Thanks, Maybe I am doing this wrong, if someone goes to the effort to add a tsconfig entry can the linting respect the tsconfig setup?

I haven’t dug through the linting rule code, but the purpose of the rule is to block accidentally depending on things you shouldn’t - but it won’t block a determined effort to bypass it

It’s not a linting error, it’s a compiler error

Because tsconfig paths point specifically to the index.ts of the library

(it used to rely on linting when we had wildcard path matching, which is no longer the case)

:point_up: also Nx 8.12.3+ uses TypeScript to resolve the imports, so deep linking is opt in (by essentially adding * to your paths in the tsconfig) and the deep import rule isnt there anymore

I believe I saw a related issue in regards to secondary entry points.

This is what I was just doing: import {foo} from '@myorg/myappgroup/somelib';

I didn’t get any warnings; just had to specify it in my tsconfig.