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.
[1] https://github.com/typings/typings/blob/master/docs/registry...
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.
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.
TS does not add any semantic features, it only adds type annotations. Which it checks at compile time, and then removes. That's it.
Want to switch away from TS? Compile all your .ts files, save the .js, check that into your repo and continue from there.
(As other commenters sort-of pointed out: you will need to keep Babel in your pipeline.)
Yes. ∀ x: I can do x in JS → I can do x in TS
But, let's assume for a second that you couldn't: this thread is about TS being future-proof. I.e.: ∃ x: I can do x in TS & I cannot do x in JS? No, false.
This implies TS = JS. And that's the point: semantically, TS = JS.
https://github.com/sebastian-lenz/typedoc/blob/master/src/li...
Your code will keep working, but it may diverge a bit from standard JS; however everything will keep working, and I'm sure the expectation would be to move over the es6's syntax unless there were semantic reasons not to.
The Typescript authors are involved in the ECMAScript process, so I'm pretty sure that there won't be any surprising huge rifts at least.
Also, there a few constructs in TypeScript that generate JavaScript code, like enum and module.
THAT SAID, TypeScript is basically ES6 + type annotations, and can certainly be used as such.
In this case, I'm hoping TS will just make the breaking change and go back to being pure, standard ES plus optional type annotations. Developers who use it would just accept that from time to time, this could happen, but it could probably be made a non-issue if MS just wrote another transpiler: oldTS -> newTS, for people whose choice of Typescript meant they had committed from the start to a system that would ALWAYS require transpiling.
But for me JS -> TS feels like C -> C++ evolution/Transition. For most of Unix utillies or even as complex as Linux Kernel, Apache, Nginx, C is good enough. In the hands of developers who master it, there are no C++ equivalent.
For after look at the v8's C++ code, I can't imagine anyone would write that with C.
But when a new language's ego system is not mature enough, the development work flow can be a nightmare. I remember trying to use GWT to compile Java into JS. The demo works and looks cool. But more often or not, I end up debug "The JAVA code" AND "The machine generated Javascript" AND "how that JS interact with different browsers" for something that is extremely trivial to do with one line of JS/JQuery code.
* Writing code is easy. * Debugging code is harder. * Make sure that code works on all the browsers are much harder.
* Debugging system with multiple languages (JS, TS, React, Angular, polymer, etc) + machine generated code is not easy.
* Integrated them all together to fixed all issues and make sure the final program will work on all browsers are > N^2, N^3, N^4 times harder?
I am old enough to admit, that is not a job for me. :-)
You're never debugging TypeScript separately from JavaScript.
declare var _: {
each<T, U>(arr: T[], f: (elem: T) => U): U[];
delay(f: Function, wait: number, ...arguments: any[]): number;
template(template: string): (model: any) => string;
bindAll(object: any, ...methodNames: string[]): void;
};
declare var Store: any;
If there is bug in this code, I won't know how to debug it.I have no clue on what the JS generated by it looks like.
If I have to ask some JS programmer with no TS experience to integrate this "ts library" into their app and make sure the integrated app works on all browsers. I would have no clue on the complexity of the task just as I have no clue on how complex it was to make the GWT generated JS app to work on all browsers.
If it is just a JQuery / JS app, I can have 80-90% confident on schedule and quality of the app delivery.
But that's me, like I said, I am too old... :-)
We can do this all day ;)
Not that I'm agreeing with the post in question, but ClojureScript and TypeScript are very different beasts.
This unfortunately makes languages like Elm and Clojurescript unlikely to be chosen in a lot of situations (e.g. as I understand it, the JS interop story with Elm isn't amazing, so you can't just use JS libraries with it).
Typescript is close enough to plain Javascript to not scare people off (I'd be willing to bet any JS developer could pick it up in a few hours) and can almost be considered in the same light as vanilla JS in such a decision, yet brings with it the advantages of a fairly decent type system.
As I've said elsewhere, it's definitely not perfect, but for developers in a position where other, more "esoteric" compile-to-JS languages aren't likely to be accepted, Typescript probably represents the best choice of bringing a decent amount of sanity and predictability to codebases.
(This isn't meant to be having a go at the parent BTW, it's just something I've been thinking about a bit and the comment jogged my memory!)
Details about our experience with Elm in production: https://www.youtube.com/watch?v=R2FtMbb-nLs
I recommend you try again and file a bug or look for help in irc if something breaks again (although I've never seen pulp init throw an error).
It's the best thing that has happened to web development in recent years - it improves Javascript in a completely compatible and future proof way.
The most amazing thing is that Microsoft created it. It's the polar opposite of Old Microsoft - standards are being followed (not subverted), it's simple pragmatic and has no lock-in.