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

Document: How to get "Simplified Declaration File (.d.ts) Acquisition" form custom repositories? #12284

Closed
scharf opened this issue Nov 16, 2016 · 8 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@scharf
Copy link

scharf commented Nov 16, 2016

When I create a pull request to DefinitelyTyped, there is normally a period between submitting the pull request until the update is available via npm install --save @typings/the-module.

During that time, I want to consume the resulting changes in my project. With typings it was easy to use my own definitions form my own repository. All I had to do was to add something a simple line to the typings.json file :

    "analytics-node": "github:scharf/DefinitelyTyped/analytics-node/index.d.ts#f872ddbb3f4958b4ba0f63bc2b066676a169c1cc",

What is the equivalent of that with the new npm based type definitions?
Is there any documentation that explains this workflow for #9184?

@Jessidhia
Copy link

package.json does support specifying a github repository and a commit hash, but not a path inside the git repository :/

Also because the individual package.json are synthesized by the publish tool, it's not trivial to use npm link. But something like npm link in DefinitelyTyped, followed by npm link DefinitelyTyped and mkdir -p node_modules/@types && ln -s ../DefinitelyTyped/yourpackage node_modules/@types/ should work.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2016

Would this address your request DefinitelyTyped/DefinitelyTyped#12392 ?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2016

npm link is definitely an option.

From the compiler perspective, the package in @types can be any where under --typeRoots. by default --typeRoots is infered to be node_modules\@types, but you can change this for your project, for instance:

{
    "compilerOptions": {
        "typeRoots": [
            "./definitions/",
            "./node_modules/@types"
        ]
    }
}

this tells the compiler when resolving a /// <reference type="package" /> to look under ./definition/package/index.d.ts first and if not found look under ./node_modules/@types/package/index.d.ts.

the other piece, is if your declaration file is a module, then you can just add it to your --baseUrl folder if you have one, or set a baseUrl. e.g.:

{
    "compilerOptions": {
        "baseUrl": "./definitions"
    }
}

For an like import * as p from "package", the compiler will look inside ./definitions/package first, then in node_modules/package then in node_modules/@types/package.

More info can be found at: www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types and www.typescriptlang.org/docs/handbook/module-resolution.html

@scharf
Copy link
Author

scharf commented Nov 16, 2016

This means, I have to add the type definitions temporarily to my project until they are officially published.

So, this makes it more complicated to switch between my temporary type definitions and the official ones. And there is a danger that the types added in that way may not behave the same way the official types behave.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2016

This means, I have to add the type definitions temporarily to my project until they are officially published.

So, this makes it more complicated to switch between my temporary type definitions and the official ones. And there is a danger that the types added in that way may not behave the same way the official types behave.

then symlinks are your best options here. use npm link as @Kovensky suggested.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Nov 16, 2016
@ccancellieri
Copy link

ccancellieri commented Nov 17, 2016

I'm currently using:
in tsconfig.json:

{...
"files": [
        "./typings-local/index.d.ts",
    ]
...}

in that file I'm specifying the list of:

/// <reference path="....d.ts" />

The mechanism you are proposing is intended to to replace the above solution? Why?

@scharf
Copy link
Author

scharf commented Nov 17, 2016

then symlinks are your best options here. use npm link as @Kovensky suggested.

This is significantly more difficult to integrate into a team workflow than the typings solution where I could point to a file in a remote repository.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2016

This is significantly more difficult to integrate into a team workflow than the typings solution where I could point to a file in a remote repository.

you can still use typings if you want. you could use symlinks, you could include the file in your combination, or you could use path mapping. up to you.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@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

4 participants