{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12495","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12495/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12495/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12495/events","html_url":"https://github.com/Microsoft/TypeScript/issues/12495","id":191653034,"number":12495,"title":"Unable to publish a package to NPM with both d.ts files and ts files","user":{"login":"Roaders","id":10414642,"avatar_url":"https://avatars.githubusercontent.com/u/10414642?v=3","gravatar_id":"","url":"https://api.github.com/users/Roaders","html_url":"https://github.com/Roaders","followers_url":"https://api.github.com/users/Roaders/followers","following_url":"https://api.github.com/users/Roaders/following{/other_user}","gists_url":"https://api.github.com/users/Roaders/gists{/gist_id}","starred_url":"https://api.github.com/users/Roaders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Roaders/subscriptions","organizations_url":"https://api.github.com/users/Roaders/orgs","repos_url":"https://api.github.com/users/Roaders/repos","events_url":"https://api.github.com/users/Roaders/events{/privacy}","received_events_url":"https://api.github.com/users/Roaders/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-25T08:59:51Z","updated_at":"2016-11-25T11:34:56Z","closed_at":null,"body":"Hi All\r\n\r\nI am trying to publish a strongly typed package to NPM that I can then use in other projects without having to manually import typing information. I have looked at this very helpful guide:\r\n\r\nhttps://medium.com/@mweststrate/how-to-create-strongly-typed-npm-modules-1e1bda23a7f4#.u17bputcb\r\n\r\nwhich got me most of the way but not all the way.\r\n\r\nConsider the following setup:\r\n\r\n**server.ts**\r\n```\r\nimport {IDatabaseConnection} from \"./contracts\"\r\n\r\nexport class MyServer{\r\n    constructor(private db: IDatabaseConenction){}\r\n}\r\n```\r\n**database.ts**\r\n```\r\nimport {IDatabaseConnection} from \"./contracts\"\r\n\r\nexport class DatabaseConnection implements IDatabaseConenction{\r\n    constructor(){}\r\n}\r\n```\r\n**contracts.d.ts**\r\n```\r\nexport interface IDatabaseConnection{}\r\n```\r\n**exports.ts**\r\n```\r\nimport * as Contracts from \"./contracts\";\r\nimport * as Database from \"./database\";\r\nimport * as Server from \"./server\";\r\n\r\nexport{Contracts, Browser, Node};\r\n```\r\n\r\nin my `package.json` I set main as `exports.js` and typings as `exports.d.ts`.\r\n\r\nThis all builds fine and can be published to npm no problem. In the project that is consuming this package I can use the types as follows:\r\n\r\n```\r\nimport * as mypackage from \"mypackage\";\r\n\r\nvar connection: mypackage.Contracts.IDatabaseConnection \r\nconnection = new mypackage.Database.DatabaseConnection();\r\nvar server = new mypackage.Server.MyServer()\r\n```\r\n\r\nThis all compiles fine as well. However, when I run it in node I get an error:\r\n\r\n`cannot find module './contracts'`\r\n\r\nThis is because the `exports.js` file is referring to `./contracts` but there is no `contracts.js` file. As it is a `d.ts` it does not produce a javascript file. The `contracts.d.ts` file is there which is why the compilation works but at runtime node dies.\r\n\r\nWhat needs to happen is at compile time of the package the `exports.js` file needs to leave out the `./contracts` import but this needs to stay in the `exports.d.ts` file.\r\nAnother solution is the ability to specify extra `d.ts` files in the `package.json` file.\r\n\r\nAt the moment I can see 2 workarounds:\r\n\r\n- turn `contracts.d.ts` into `.ts` file and include an empty `.js` file in our package\r\n- have the consumer of the package add a reference to `node_modules/mypackage/contracts.d.ts`. This is not good as it requires knowledge of the internals of the package."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/262938294","html_url":"https://github.com/Microsoft/TypeScript/issues/12495#issuecomment-262938294","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12495","id":262938294,"user":{"login":"pocesar","id":461084,"avatar_url":"https://avatars.githubusercontent.com/u/461084?v=3","gravatar_id":"","url":"https://api.github.com/users/pocesar","html_url":"https://github.com/pocesar","followers_url":"https://api.github.com/users/pocesar/followers","following_url":"https://api.github.com/users/pocesar/following{/other_user}","gists_url":"https://api.github.com/users/pocesar/gists{/gist_id}","starred_url":"https://api.github.com/users/pocesar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pocesar/subscriptions","organizations_url":"https://api.github.com/users/pocesar/orgs","repos_url":"https://api.github.com/users/pocesar/repos","events_url":"https://api.github.com/users/pocesar/events{/privacy}","received_events_url":"https://api.github.com/users/pocesar/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T11:34:56Z","updated_at":"2016-11-25T11:34:56Z","body":"the generated .d.ts file uses `/// <reference` at the top, it also deals with importing interfaces from other files. if you build it using `declarations: true` in compilerOptions, you won't have to do this manually"}}
{"actor":{"display_login":"pocesar"}}