Skip to content

Custom Typings - How To #11329

Closed
Closed

Description

@MCKRUZ

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?

Activity

  1. mhegazy commented on Oct 3, 2016

    @mhegazy
    Contributor

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

  2. MCKRUZ commented on Oct 3, 2016

    @MCKRUZ
    Author

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

  3. MCKRUZ commented on Oct 3, 2016

    @MCKRUZ
    Author

    so it doesn't appear in the typings folder

  4. mhegazy commented on Oct 3, 2016

    @mhegazy
    Contributor

    is it a module?

  5. MCKRUZ commented on Oct 3, 2016

    @MCKRUZ
    Author

    Yes it is

  6. mhegazy commented on Oct 3, 2016

    @mhegazy
    Contributor

    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?

  7. mhegazy commented on Oct 3, 2016

    @mhegazy
    Contributor

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

  8. towertop commented on Nov 18, 2016

    @towertop

    Mohamed Hegazy (@mhegazy)

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

  9. mhegazy commented on Nov 18, 2016

    @mhegazy
    Contributor

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

    what are you trying to do?

  10. DanielRosenwasser commented on Nov 18, 2016

    @DanielRosenwasser
    Member

    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.

  11. weswigham commented on Nov 19, 2016

    @weswigham
    Member

    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?

  12. towertop commented on Nov 21, 2016

    @towertop

    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.

  13. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions