JavaScript Schema
Modeling local JS APIs with an extended variant of JSON Schema

Type Checking in Javascript

Type checking Javascript usually uses some additional meta-information that is typically attached to the code in the form of JsDoc comments. The most popular project using this approach is probably Google's JsCompiler.

But what if we want to perform Javascript type checking (for code using the built-in browser API) in JavaScript? Ideally, we'd have type information available in a format that is really easy to read from JavaScript.

JSON Schema -> JavaScript Schema

JSON Schema does this for JSON, but of course it just covers JSON objects (= simple structs). So for our purpose, we need to cover live objects with constructors and methods.

Fortunately, it's quite straight forward to extend JSON Schema accordingly: We can just add "constructors" and "operations" fields at the same level as "properties", model parameters below, and we are basically done. We can just introduce a "function" type (containing the return type and parameter types) and add "constructors" at the same levelas "properties".

Examples

I haven't written up an extended JSON Meta-Schema for this yet, but generated some examples from the HTML 5 spec already.

I don't think this is fully complete / correct yet, but I wanted to start looking into using this for actual type checking (using Esprima) before refining the format some more.

Comments or Suggestions? Use this G+-Post.