3 ms·
I love Typescript, I do all my javascript coding via it. However, Though I wish it were, Typescript is NOT currently suitable for defining modules for extern
by novaleaf 11y ago
I love Typescript, I do all my javascript coding via it.
However, Though I wish it were, Typescript is NOT currently suitable for defining modules for external consumption. The problem comes down to no effective means of publishing the typings of your project and your project's dependencies. For example, if your project uses Promises, you might choose to include a definition of those promises, or (worse) reference a Promise typing you found on DefinitelyTyped. This will work fine for you, the publisher. But any consumer of your project will be rudely greeted with typing collisions: Things like "The interface 'Promise' already exists in es6.d.ts"
There needs to be a solution to this module publishing problem before people can seriously publish modules (using NPM) using Typescript. Unfortunately, I have been tracking this issue and there is no timeline for resolving it, mostly due to too many different module systems, and handling module publishing being outside the design-scope of Typescript.
- lloyd-christmas 11y agotypings[1] does exactly that as long as people start publishing their definitions (which is kind of the point of them). Relying on un-versioned ambient declarations is what breaks things, not having dependencies. [1] https://github.com/typings/typings/blob/master/docs/registry.md https://github.com/typings/typings/blob/master/docs/registry...
- novaleaf 11y agothanks for the link. I'm partially aware of typings, but too into my own implementation right now to consider switching fro definitely typed. I'll give it a try and pray it actually can let me ship an OSS project!
- lloyd-christmas 11y agoFor a quick and small example to see it in action: npm init && typings init npm install debug ms --save typings install debug ms --save debug is dependent on ms, so in node_modules you have: |-ms |-debug | |-ms typings/main/definitions will have |-debug | |-index.d.ts |-ms | |-index.d.ts It makes up for this file structure by declaring modules named in a file-like structure so the entire dependency tree is self contained in one file, while only exposing it's own typings through the final export declarations "debug" and "ms". No stepping on toes. Best to see for yourself, it would take a bit to write down. As a point of info, it only works when people start adding versioning to the typings registry itself. debug and ms are both versioned in the registry, which is the only reason their dependencies are correctly managed. DefinitelyTyped ambient declarations will still break things. Until those are gone and everything is versioned, you'll still need some hacking depending on your dependencies. That being said, I've seen the issues start to fade rather quickly given the short time period I've been using it.
- carussell 11y agoTypeScript has support for namespaces, and `import` gives you a lot of flexibility. If these aren't sufficient to handle the problem you describe, can you explain how? Can you post a link to the issue you are watching so we can see a better description of the problem you're running into?
- novaleaf 11y agoHere's a scenario: You write a library that uses Promises, and use bluebird.d.ts for that definition. For someone to use your library, they will have to download bluebird.d.ts manually and include it. if you (the lib dev) include it yourself, then any other definition of Promise (including if the user has their own bluebird.d.ts definition included) will cause typing collisions. As someone mentioned, the Typings project might solve this, but there isn't very good communication on this project and the problems it's supposed to solve.