Open KrofDrakula opened 1 year ago
Here's a quick workaround.
import { JSDocableNode, PropertyAssignment } from "ts-morph";
// HACK: Patch the PropertyAssignment class to add JSDoc support
// https://github.com/dsherret/ts-morph/issues/1379
const properties = Object.getOwnPropertyDescriptors(
JSDocableNode(PropertyAssignment as any).prototype
);
delete (properties as any).constructor;
Object.defineProperties(PropertyAssignment.prototype, properties);
declare module "ts-morph" {
interface PropertyAssignment extends JSDocableNode {}
}
I am seeing a similar situation for VariableDeclaration
s.
Simple constant declaration such as
/**
* @internal
*/
export const gcTombstoneBlobKey = "__tombstones";
is not JSDocableNode
. VariableDeclaration
and others are missing from Node.isJSDocable
's list.
For the case I hit, I was enumerating ExportedDeclarations
and trying to find tags. After further fiddling I found that walking ancestors of VariableDeclaration
will get to VariableDeclarationList
and then VariableStatement
which is JSDocable
. So, I guess VariableDeclaration
is not missing, just different compared to other exports I've come across.
Describe the bug
Version: 17.0.1
When trying to extract JSDocs for a property assignment, the underlying compiler node provides the documentation, but
ts-morph
does not provide an accessor method, and mistakenly identifiesPropertyAssignment
as not JSDocable.To Reproduce
Run
npm test
in the console to demonstrate the test passing but types erroring out:https://stackblitz.com/edit/vitejs-vite-an78pr?file=src/index.test.ts
The passing test illustrates that the JSDoc is available on the
compilerNode
, but the wrapped type does not contain thejsDoc
property, nor does it provide agetJsDocs()
method on the node, even though it should.