javascript - Använda en importerad typ i JSDoc @typedef
Jag försöker minska duplicering när jag specificerar mina importerade typer på följande sätt, men jag får ett fel
/**
@typedef {import("../types/util")} util
@typedef {util.mapBehaviors} mapBehaviors
... lots of other typedefs based on util
*/
'util' only refers to a type, but is being used as a namespace here.
Det är konstigt eftersom att explicit utvidga importen fungerar:
/**
@typedef {import("../types/util").mapBehaviors} mapBehaviors
... lots of other typedefs
*/
Hur kan jag använda @typedef med ett alias för en import?
Svar #1
Detta kan hända om du endast exporterar interface eller type från din .d.ts-fil och inte function eller const.
Detta kommer att fungera:
/**
@typedef {import("../types/types").util} util
@typedef {util["mapBehaviors"]} mapBehaviors
...
*/
men bara om du i util.d.ts har
export function mapBehaviors(tags: string[] | Behavior[], table: Behaviors): Behavior[]
...
istället för
export interface mapBehaviors {
(tags: string[] | Behavior[], table: Behaviors): Behavior[]
}
