Zsolt Szatmari
Zsolt Szatmari

Reputation: 1239

What is a good solution for annotating javascript for static type checking?

what is a good solution for annotating javascript for static type checking?

Personally I have experience with TypeScript, and I like it, but the problem is that it has an overhead: If you want to work with others, either they learn TypeScript, or you downgrade to plain untyped Javascript. I know jsdoc and the closure compiler, possibly others can statically typecheck javascript based on declarations in comment blocks. What is a suggested solution today? Also, the typechecking should be over module boundaries as well (I am referring require(...) and pals)

Thank You!

Edit: It would be a plus, if variables could be annotated as constant. Even better, if the objects themselves could be annotated as immutable, but I realize that I am asking too much.

Upvotes: 0

Views: 129

Answers (2)

Ezward
Ezward

Reputation: 17702

Facebook Flow now supports putting type annotations within block comments, so the source javascript is still valid javascript. See here: http://flowtype.org/blog/2015/02/20/Flow-Comments.html

Upvotes: 1

mgerton
mgerton

Reputation: 31

Facebook recently released Flow, a static type-checker for JavaScript. This seems like it might fit what you're looking for.

Upvotes: 1

Related Questions