You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a generic function that generates a set of typed functions. You can think if it as it generates an API for the type. Then I have a function that generates a collection of APIs for some types.
I'd like to mark these as namespaces but I'm not having any luck.
Here's some sample code
exporttypeBaseArgType=Float32Array|Float64Array|number[];exporttypeVecArg=BaseArgType;/** * A specific concrete Vector Type */exporttypeVecType<TextendsVecArg>=T;typeVecCtor<TextendsVecArg>=new(n: number)=>T;/** * Generates a typed API */exportfunctiongetFooAPIImpl<VecTypeextendsVecArg>(Ctor: VecCtor<VecType>){/** * Adds two vectors; assumes a and b have the same dimension. * @param a - Operand vector. * @param b - Operand vector. * @param dst - vector to hold result. If not passed in a new one is created. * @returns A vector that is the sum of a and b. */functionadd<TextendsVecArg=VecType>(a: VecArg,b: VecArg,dst?: T){constnewDst=(dst??newCtor(3))asT;newDst[0]=a[0]+b[0];newDst[1]=a[1]+b[1];newDst[2]=a[2]+b[2];returnnewDst;}/** * Subtracts two vectors. * @param a - Operand vector. * @param b - Operand vector. * @param dst - vector to hold result. If not passed in a new one is created. * @returns A vector that is the difference of a and b. */functionsubtract<TextendsVecArg=VecType>(a: VecArg,b: VecArg,dst?: T){constnewDst=(dst??newCtor(3))asT;newDst[0]=a[0]-b[0];newDst[1]=a[1]-b[1];newDst[2]=a[2]-b[2];returnnewDst;}return{
add,
subtract,};}exportfunctiongetBarAPIImpl<VecTypeextendsVecArg=Float32Array>(Ctor: VecCtor<VecType>){/** * Multiplies a vector by another vector (component-wise); assumes a and * b have the same length. * @param a - Operand vector. * @param b - Operand vector. * @param dst - vector to hold result. If not passed in a new one is created. * @returns The vector of products of entries of a and b. */functionmultiply<TextendsVecArg=VecType>(a: VecArg,b: VecArg,dst?: T){constnewDst=(dst??newCtor(3))asT;newDst[0]=a[0]*b[0];newDst[1]=a[1]*b[1];newDst[2]=a[2]*b[2];returnnewDst;}/** * Divides a vector by another vector (component-wise); assumes a and * b have the same length. * @param a - Operand vector. * @param b - Operand vector. * @param dst - vector to hold result. If not passed in a new one is created. * @returns The vector of quotients of entries of a and b. */functiondivide<TextendsVecArg=VecType>(a: VecArg,b: VecArg,dst?: T){constnewDst=(dst??newCtor(3))asT;newDst[0]=a[0]/b[0];newDst[1]=a[1]/b[1];newDst[2]=a[2]/b[2];returnnewDst;}return{
multiply,
divide,};}/** * Don't need docs for this * @param Ctor1 - Constructor for FooAPI vectors * @param Ctor2 - Constructor for BarAPI vectors * @returns An object containing both Foo and Bar APIs */functiongetAPIs<T1extendsVecArg,T2extendsVecArg,>(Ctor1: VecCtor<T1>,Ctor2: VecCtor<T2>,){/** @namespace */constfoo=getFooAPIImpl<T1>(Ctor1);/** @namespace */constbar=getBarAPIImpl<T2>(Ctor2);return{ foo, bar };}/** @namespace */exportconstf32API=getAPIs(Float32Array,Float32Array);/** @namespace */exportconstf64API=getAPIs(Float64Array,Float64Array);
With 0.25 this isn't supported - @namespace is only permitted on variable declarations, and TypeDoc will actually crash if you put it somewhere else.
With 0.26, I just made it so that the following will work:
return{/** A comment @namespace*/
a,/** B comment @namespace */b: getApi(Ctor2),};
Note that the comment is within the return object not on the variable declaration. While comments on the declaration work for functions (due to being attached to the signature, not the symbol) TS considers the appearance in the return object to be the source declaration.
Search terms
"namespace" finds #2055
Question
I have a generic function that generates a set of typed functions. You can think if it as it generates an API for the type. Then I have a function that generates a collection of APIs for some types.
I'd like to mark these as namespaces but I'm not having any luck.
Here's some sample code
What I'm hoping to get is
Where
[N]
= namespace and[F]
= functionWhat I get instead is
Where
[N]
namespace and[V]
= variableAnd then, clicking
foo
orbar
brings up a single page for that branch with all the functions on itIs there a tag I can add that would do this or a way to restructure my code that would do this or is maybe typedoc not able to do this at the moment?
The text was updated successfully, but these errors were encountered: