Externs are valid javascript, but they are just type information. They should not contain definitions (or for functions only empty definitions).
Here's a start: How to Write Closure-compiler Extern Files Part 1
A couple of notes on your specific example:
- Don't use an anonymous wrapper. Type names must be global.
- Properties on the window object are the same as the namespace examples.
- Functions shouldn't have implementations
Here's a corrected example:
/** @const */
window.myapi = {};
/** @return {undefined} */
window.myapi.hello = function() {};
In Closure-compiler properties on the window
(global) object are seen completely differently than global variables. If you need both, you'll have to declare everything twice.
/** @const */
var myapi = {};
/** @return {undefined} */
myapi.hello = function() {};