Structural Considerations
Domain Isolation?
If a domain isolation is strong, you don't necessarily have to extract out the module the same structure as other domains
- e.g. if you're using a
service/repository/gatewaysplit- you don't have to extract out
gatewayfrom the same directory as aservicewhen the domain isolation is strong
- you don't have to extract out
Public Contract
Export symbols through public contract (index.ts)
- avoid deep imports and only use public exports
- don’t reference file, reference folder names
index.tsis a JS feature to reference default export of a directory
- don’t reference file, reference folder names
What does this mean: export/import of type references only in index
- If the referenced is not in
index, it shouldn’t be referenced and abstracted away
Class as Type
Classitself can be an interface contract
Since instantiation of class is an object (what essentially Interface achieves), you can use the Class directly as the interface
// Bclass.js import Aclass from "./Aclass.js"; export class Bclass { constructor(private a: Aclass) { ... } }
Another Valid Example
class Person { "name": "sam" } let s = "hello"; let n: Person; n = { "name": "sam", }