0

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Nice, but from what I've seen on it's official homepage, it suffers the same 'overhead' as TypeScript, although a lesser extent as type annotated flow code is not valid js,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.