Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Typings - How To #11329

Closed
MCKRUZ opened this issue Oct 3, 2016 · 12 comments
Closed

Custom Typings - How To #11329

MCKRUZ opened this issue Oct 3, 2016 · 12 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@MCKRUZ
Copy link

MCKRUZ commented Oct 3, 2016

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?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 3, 2016

What do you mean by "Custom Typings"? what are you looking for specifically?

@MCKRUZ
Copy link
Author

MCKRUZ commented Oct 3, 2016

meaning that if I create a NPM library that isn't hosted in NPM but rather a private repo.

@MCKRUZ
Copy link
Author

MCKRUZ commented Oct 3, 2016

so it doesn't appear in the typings folder

@mhegazy
Copy link
Contributor

mhegazy commented Oct 3, 2016

is it a module?

@MCKRUZ
Copy link
Author

MCKRUZ commented Oct 3, 2016

Yes it is

@mhegazy
Copy link
Contributor

mhegazy commented Oct 3, 2016

so let's say you have your declaration file for the module in @private\module\index.d.ts. You can add a path mapping for it.

{
    "compilerOptions": {
        "baseUrl": "./",
        "paths":{
            "@private/*": ["types/@private/*"]
        }
    }
}

would this work?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 3, 2016

The ideal case would be the use of typeRoots to inject the additional directory. but this needs #11137 to be fixed first.

@towertop
Copy link

@mhegazy

So what the "paths" options is designed for? That confuses me.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2016

So what the "paths" options is designed for? That confuses me.

what are you trying to do?

@DanielRosenwasser
Copy link
Member

@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.

@weswigham
Copy link
Member

weswigham commented 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
Copy link

Thanks @DanielRosenwasser , I got it.

@mhegazy I was confused which is preferred when "typeRoots" and "paths" both help to patch declarations for external module.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Nov 22, 2016
@mhegazy mhegazy closed this as completed Dec 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants