Please enable JavaScript.
Coggle requires JavaScript to display documents.
Typescript Advanced - Coggle Diagram
Typescript Advanced
Modules
introduction
what is it
breaks code into multiple files
you use this a lot already
why care
cleaner code
low coupling
when to use
"single responsibility principle"
exporting
re-exporting
good for NPM modules
e.g
export {function as functionName} from './otherModule'
re-exporting all
e.g
export * as otherModule from './otherModule'
importing
importing types
e.g
import type {interfaceName} from './utils'
babel will clean them all on build
ambient modules
(d.ts files)
what is it
a file to declare types
usually paired with non-typescript language like JS
characteristics
DOES NOT declare implementation detials
example
017a459c70c7022ef4b4968648fde454
Declaration Merging
introduction
what is it
merges two or more types in typescript
union
process
why care
modifying existing libraries
composite existing type
merging
interface
namespace
with other namespace
with class
with interface
module augmentation
what is it
declaration merging on
node_modules
library
you don't have control on those modules,
so you trick it
how to do it
import the library's interface module
declare module with the same name
so it merges
Namespaces
introduction
what is it
a.k.a local module
groups related code as one
high cohesion
why care
compiles to
IIFE
Immediately Invoked Function Expression
controls scope of a variable
high cohesion
when to use
high cohesion
controls scope
needs further research!!!