How to add module-level documentation to ambient module? - typedoc

We have a bunch of ambient module declarations for our JS library (mostly to provide support in VSCode, nobody actually uses it from TypeScript yet). We are trying to add TypeDoc documentation for the modules as a whole.
In previous versions of TypeDoc, this used to work:
file: u-components.d.ts
/**
* This module does blah blah...
* #packageDocumentation
*/
declare module "u-components" {
import ...
"This module does blah blah..." would be output at the top of the module documentation.
However, in TypeDoc 0.23.x this stopped working and it no longer does anything with the top level documentation.
How do we add module level docs for ambient module declared like this?

Related

the library (#circlon/angular-tree-component) which declares TreeModel has not been processed correctly by ngcc, is not compatible with Angular Ivy

ERROR in node_modules/#circlon/angular-tree-component/lib/models/tree.model.d.ts:7:22 - error
i am trying to use #circlon/angular-tree-component for the menu in tree-view with checkboxes.
and throws error something like...
NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the library (#circlon/angular-tree-component) which declares TreeModel has not been processed correctly
by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.
7 export declare class TreeModel implements ITreeModel, OnDestroy {
how to resolve this...?
thanx.

Globally-available mixin in VueJS

I'm trying to create a mixin that's globally available, but not automatically injected into every component. i.e. i do NOT want this: Vue.mixin({...});
I set up the project according to these instructions. This is my project structure. I also have assets/js/mixins.js file in there containing my mixins.
I would like to be able to do this in my individual .vue files (many of my components use myMixin but not all of them):
<script>
export default {
mixins:[myMixin],
data:{....}
}
</script>
<template>
<!-- some template code -->
</template>
So far the only way to do that is to add this line to the top of every component that needs it:
import {myMixin} from './assets/js/mixins.js"
but is there a way to do this once and have myMixin variable available globally? I've tried including it in main.js and in app.vue but I still get "myMixin is not defined" error if I try to use myMixin in any of the child components.
Or is there another way to register a mixin that doesn't require me typing the path to the mixins.js file in each component?
I would suggest setting your mixin up as a plugin. To do that, wrap it within an function call install and export the install function. Then, wherever your instantiate your app, you can simply do Vue.use(yourMixin):
Docs:
https://vuejs.org/guide/plugins.html
http://vuejs.org/api/#Vue-mixin
Example:
//- build your mixin
const mixin = {
// do something
}
//- export it as a plugin
export default {
install (Vue, options) {
Vue.mixin(mixin)
}
}
//- make it globally available
import myMixin from './myMixin'
Vue.use(myMixin)
Vue.use calls in the install fn(), so all subsequent Vues (or all if none have yet been created) have the mixin functionality
Careful of namespace clashes on globally available mixins (!)
A couple of ideas:
In main.js you can declare window.myMixin = {...}, which I believe will make it available in any component loaded after that.
edit: this is even better if you use this.myMixin, as this will refer to the global scope. That way you aren't depending on window existing, so it could be used in more environments
To not have to declare the full path in each file, you could create the mixin as a local NPM module as per Installing a local module using npm?. Then you could just import myMixin from 'myMixin'. This would be the more proper way to do it I think, that way you're still loading dependencies in each component, just with some shorthand.
Here is the correct way to register a mixin globally in app.js
Vue.mixin(myMixin);

Export objects and classes before their declaration makes them undefined

I try to repeat example from Mozilla Hacks (Export lists subtitle):
//export.js
export {detectCats, Kittydar};
function detectCats() {}
class Kittydar {}
//import.js
import {detectCats, Kittydar} from "./export.js";
console.log(detectCats); // function detectCats() {}
console.log(Kittydar); // undefined
Oops: Kittydar is undefined (btw., the problem is the same with simple Object).
But if I put export after Kittydar declaration it's ok:
//export.js
class Kittydar {}
export {Kittydar};
//import.js
import {Kittydar} from "./export.js";
console.log(Kittydar); // function Kittydar() {_classCallCheck(this, Kittydar);}
Is this a typo in the article?
I transpile this with babel and bundle with browserify. Then I include output bundle in a usual .html file (with <script> tag).
The standard is hard to follow on this, but the article is correct. This code works in es6draft and in the SpiderMonkey shell: both the function and the class are initialized by the time those console.log calls run.
Here's how it's supposed to work, in minute detail:
The JS engine parses import.js. It sees the import declaration, so then it loads export.js and parses it as well.
Before actually running any of the code, the system creates both module scopes and populates them with all the top-level bindings that are declared in each module. (The spec calls this ModuleDeclarationInstantiation.) A Kittydar binding is created in export.js, but it's uninitialized for now.
In import.js, a Kittydar import binding is created. It's an alias for the Kittydar binding in export.js.
export.js runs. The class is created. Kittydar is initialized.
import.js runs. Both console.log() calls work fine.
Babel's implementation of ES6 modules is nonstandard.
I think it's deliberate. Babel aims to compile ES6 modules into ES5 code that works with an existing module system of your choice: you can have it spit out AMD modules, UMD, CommonJS, etc. So if you ask for AMD output, your code might be ES6 modules, but the ES5 output is an AMD module and it's going to behave like an AMD module.
Babel could probably be more standard-compliant while still integrating nicely with the various module systems, but there are tradeoffs.

Loading a global module in ECMAScript 6

Some old Javascript libraries directly attach an object to the global scope (no AMD, no UMD, no commonJS).
Is there a nice way to "include" a global module in ECMAScript 6 code?
I'm just aware of the following line:
import './globallib.js';
And then access the global variable directly.
Example: to load QUnit test function:
import 'qunit';
test('my test', function () {
ok(true, 'QUnit loaded');
});
Is this the right way?
PS. I encountered this problem while working with QUnit 1.8 in a project that compiles to ES 5 using Babel and Browserify. In QUnit 2 they're gonna avoid globals. But I have this question in general.
As far the QUnit exports its methods into window (according source code), you right, import expression is enough.
But anyway, you can't use raw imports in browsers, so you have to use some preprocessing. Webpack and browserify will work for you, but it would not be so for another build systems.

Force function documentation in Doxygen for documenting JavaScript API

I use Doxygen for documenting the JavaScript API of my C++ (Qt) project. The idea is to write one specific documentation for the JavaScript interfaces, and one for the C++ classes us usual.
One example (datasource.dox) looks like this:
\addtogroup JavaScriptAPI
#{
...
\class DataSource
\brief DataSource is the .... some doc goes here ....
\section formats Supported formats
....
\fn isOpen()
\brief returns true if the data source is currently open...
...
#}
The generated help looks nice w.r.t. the class description (or 'object'-description), but the function documentation (isOpen(), ...) is missing. Doxygen creates warning messages like:
Warning: documented function `bool isOpen' was not declared or defined.
The question, now: can I somehow force doxygen to use my \fn-d function descriptions? It would be nice, if doxygen created all those member indices for me...
Two approaches for using doxygen with Javascript are listed here http://www.doxygen.org/helpers.html
(look for JavaScript)