Dev UX: auto imports | Dev UX: contextual naming | Perf: tree shaking | Dev UX: namespace/type merging | |
---|---|---|---|---|
namespace import | not yet | yes | maybe | no |
TS namespace | yes | yes | no | yes |
types: namespace import / values: named import | not yet / yes | yes / no | yes | no |
types: TS namespace / values: named import | yes | yes / no | yes | yes |
Last active
August 20, 2019 13:21
-
-
Save OliverJAsh/f220fc030210f3cfe814f0e06c584418 to your computer and use it in GitHub Desktop.
Final thoughts
namespace
keyword to aggregate typesTable of contents
namespace
keyword to aggregate typesnamespace
keyword to aggregate valuesCode sample
unsplash-web/src/services/Unsplash.ts
unsplash-web/src/side-effects.ts
Dos and don'ts
DO use the
namespace
keyword to aggregate typesDO NOT use the
namespace
keyword to aggregate valuesnamespace
contains values, the generated code includes bloated, non-tree-shakeableobjects
non-affordable. When you see a
Collection
, what canyou do with it? Is it an interface? Is it a namespace? Is it a class? Should you call it,
instantiate it, access its members?
"no-namespace": [true, "allow-declarations"]
DO separate your API schema from application-specific types
where you should put a boundary.
depends on the API. The API is agnostic towards its clients. Separating your API types from
application-specific types reflects that relationship.
that decision now. We can keep our helpers where they are right now — in our repository.
DO use declaration (d.ts) files to store your types
DO use declaration merging to organize sibling types
Collection.Type
orCollection.Union
)DO NOT pick a "default" entity when aggregating types
DO NOT use namespace imports
Namespace imports create the risk ofNo longer the case?accidentally import types and values (see above)
Collection.Collection
and there is no way to reducethe amount of context. We should add no more context to a name than is necessary. To the contrary,
named exports can be given more context if they don't have enough
(
import { Collection as UnsplashCollection } from 'unsplash'
).Checklist
when needed.
Type
orEntity
in the type name