You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can someone please once and for all post how to do custom typings in Typescript 2.0+. I have seen multiple answers all over stackoverflow and other sites all of which are wrong. Can someone from the team please let me know what the deal is?
Edward (@towertop) The paths field is useful to align TypeScript's module resolution process with that of your module loader (e.g. AMD, System.js), or for adding custom declarations that exist outside of the standard resolution locations.
Its higher effort, but, IMO, a much neater solution than managing mappings within your tsconfig. Since your package is private, why not have a private package for its types?
Activity
mhegazy commentedon Oct 3, 2016
What do you mean by "Custom Typings"? what are you looking for specifically?
MCKRUZ commentedon Oct 3, 2016
meaning that if I create a NPM library that isn't hosted in NPM but rather a private repo.
MCKRUZ commentedon Oct 3, 2016
so it doesn't appear in the typings folder
mhegazy commentedon Oct 3, 2016
is it a module?
MCKRUZ commentedon Oct 3, 2016
Yes it is
mhegazy commentedon Oct 3, 2016
so let's say you have your declaration file for the module in
@private\module\index.d.ts. You can add apathmapping for it.{ "compilerOptions": { "baseUrl": "./", "paths":{ "@private/*": ["types/@private/*"] } } }would this work?
mhegazy commentedon Oct 3, 2016
The ideal case would be the use of
typeRootsto inject the additional directory. but this needs #11137 to be fixed first.towertop commentedon Nov 18, 2016
Mohamed Hegazy (@mhegazy)
So what the "paths" options is designed for? That confuses me.
mhegazy commentedon Nov 18, 2016
what are you trying to do?
DanielRosenwasser commentedon Nov 18, 2016
Edward (@towertop) The
pathsfield is useful to align TypeScript's module resolution process with that of your module loader (e.g. AMD, System.js), or for adding custom declarations that exist outside of the standard resolution locations.weswigham commentedon Nov 19, 2016
Alternatively: Since your packages are private, write your own private @types/module-name package, then point npm at it via your package.json.
Its higher effort, but, IMO, a much neater solution than managing mappings within your tsconfig. Since your package is private, why not have a private package for its types?
towertop commentedon Nov 21, 2016
Thanks Daniel Rosenwasser (@DanielRosenwasser) , I got it.
Mohamed Hegazy (@mhegazy) I was confused which is preferred when "typeRoots" and "paths" both help to patch declarations for external module.