Fireship · @fireship
Short Imports with TypeScript Path Mapping
Uploaded January 6, 2018 · Length 4:32
Summary
typescript path mapping for angular projects to eliminate long relative paths
- typescript path mapping
- angular productivity booster
- relative paths
- typescript namespace
- angular module imports
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
I need to start this video off on a sad
- 0:04
note on New Year's Day I lost my father
- 0:07
unexpectedly at the age of 57 he lived a
- 0:10
good full life but I just want to remind
- 0:12
everybody to enjoy the time you have
- 0:13
with your family because it can end
- 0:15
before you know it I'd like to say thank
- 0:17
you to everybody who supports this
- 0:19
project and I look forward to bringing
- 0:21
you a whole bunch of awesome resources
- 0:22
in 2018 to kick things off I'm going to
- 0:25
give you a quick angular productivity
- 0:27
booster to eliminate long relative paths
- 0:29
that look like this to a single global
- 0:32
namespace this means you can give all of
- 0:34
your feature modules a specific
- 0:36
namespace and you never really have to
- 0:38
worry about relative paths within your
- 0:39
project to demonstrate this I'm starting
- 0:42
off in a brand new angular 5 app and I'm
- 0:45
going to generate a couple of ng modules
- 0:47
first one being Corps second one being
- 0:50
shared from there I'm going to generate
- 0:53
a service inside of the core module
- 0:55
we'll just go ahead and call this the
- 0:56
off service then I'm going to generate a
- 0:59
component but for no reason at all I'm
- 1:01
going to nest this deeply within the
- 1:03
file structure of the project let's go
- 1:06
ahead and call it the deeply nested user
- 1:08
login component then if we look at the
- 1:11
file structure on the left you can see
- 1:12
the actual component file itself is
- 1:15
nested about six levels deep within our
- 1:17
project this isn't really a problem
- 1:19
unless we need to import this file in a
- 1:22
different file that's nested higher up
- 1:24
so let's try this by importing the
- 1:26
service into the component just a quick
- 1:28
side tip here whenever you import a file
- 1:30
in typescript start with empty
- 1:32
parentheses then type out the path so
- 1:34
you can use typescript autocomplete from
- 1:36
your IDE and save yourself a few extra
- 1:38
characters of typing at this point we're
- 1:42
going to have to traverse up the file
- 1:44
structure so we do dot dot slash a whole
- 1:46
bunch of times until we finally get to
- 1:48
our core module then we go in there and
- 1:50
grab the off service if you're an
- 1:53
angular developer you probably get
- 1:55
really annoyed if you have to do this
- 1:56
frequently in a large complex file
- 1:58
structure it also becomes a problem if


