Open xiaoxiangmoe opened 2 years ago
Use case:
class Foo {
/**
* @typedef {object} FooOptions
* @prop {boolean} [verbose]
*/
/**
* @param {FooOptions} opts
*/
constructor(opts = {}) {
/** @type {Required<FooOptions>} */
this.opts = {
verbose: false,
...opts,
};
}
}
In the project containing Foo
, typedoc complains that FooOptions
isn't exported, and can't generate any documentation other than the type name.
Next, I'd like to subclass Foo
in another project. I'd like to pass a FooOptions
into that subclass. I can get there with ConstructorParameters<typeof Foo>[0]
, but that's pretty difficult to document. I suppose I could also copy in the definition of FooOptions
, but then I'm just back to the first problem.
A suggestion for an approach that might work, different from the one suggested in the original issue might be:
@export
export
export default
(I don't feel strongly about this, but it's not worth adding more syntax, in my opinion)@typedef
, @callback
, and perhaps some @template
blocksexport type
to be generated into the .d.ts
file.d.ts
file, instead of expanding the type before generation.@export
is not required if the type is otherwise exposed. For example, if it is used as a parameter to an exported function or method.For the example above, instead of generating this:
export class Foo {
constructor(opts?: {
verbose?: boolean | undefined;
});
opts: Required<{
verbose?: boolean | undefined;
}>;
}
You would get this:
export interface FooOptions {
verbose?: boolean | undefined;
}
export class Foo {
constructor(opts?: FooOptions);
opts: Required<FooOptions>;
}
Now that typescript 5.5 have brought the @import
syntax, it would be nice to have the @export syntax
also it does not seem possible to use @typedef
to re-export a type imported with @import
use case exemple
/** @import {MyType} from 'my-module' */
/** @export MyType */
example corresponding typescript syntax
import type {MyType} from 'my-module'
export type {MyType}
Suggestion
🔍 Search Terms
JSDoc
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
📃 Motivating Example
Can we export AjaxStatus to other files?
such as
💻 Use Cases
Used for JavaScript development using the TypeScript language service.