typescript - What is behind the ‘@’ sign in @angular or @types? -
i trying understand behind ‘@’ sign when see import statements below:
import { injectable } ‘@angular/core’; or npm cli commands below:
npm -install –save @types/lodash the statements or commands working fine me, want learn happening behind scene of @ sign.
is '@' typescript feature? or npm thing?
a pointer in-depth online documentation great help.
it's npm thing called scoped packages. here official doc:
scopes namespaces npm modules. if package's name begins @, scoped package. scope in between @ , slash.
all scoped packages stored inside folder begins @. example, angular packages stored inside @angular folder in node_modules, whereas if there no @ scoped identifier , used angular/core , angular/compiler have separate folder each package. , same holds @types package.
how typescript import statement recognizes or integrates '@'?
the require function used node can traverse node_modules folder if use forward slash in path , it's not limited scoped packages:
node_modules b index.js module.exports = 3; m.js console.log(require('a/b')); // logs 3 typescript compiler uses node's statsync function under hood check folder:
function filesystementryexists(path, entrykind) { try { var stat = _fs.statsync(path); switch (entrykind) { case 0 /* file */: return stat.isfile(); case 1 /* directory */: return stat.isdirectory(); } } catch (e) { return false; } } and naturally function treats forward slash path separator. when resolving path typescript compiler prepends node_modules path if node module resolution strategy set.
Comments
Post a Comment