dsherret / dsherret/ts-morph

Adding a JS doc on a property signature (of a literal type) only works from 2nd call

Open
#1,183 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

I'm trying to add a comment (jsdoc) to a property signature node (of a type literal node) and experiencing a strange behavior. It works only on the 2nd `addJsDoc` call.

Version: 11.0.3

**To Reproduce**

```ts
const { Project, SyntaxKind } = require('ts-morph');

const project = new Project();

const sourceFile = project.createSourceFile('index.ts', `
interface Foo {
someLitral: { someString: string }
}
`);

const propSignature = sourceFile.getInterface('Foo')
.getProperty('someLitral')
.getTypeNode()
.getProperty('someString');

propSignature.addJsDoc('some comment'); // 1st call, doesn't work

console.log(propSignature.print());

// => "someString: string;"

propSignature.addJsDoc('some comment'); // 2nd call, works

console.log(propSignature.print());

// => "/** some comment */\nsomeString: string;"
```

**UPDATE**

Ok, seems like when I call `save` on the file, it does save it correctly with the comment in place. So it appears somewhere, just doesn't `print` it.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the TypeScript snippet using property signatures, addJsDoc(), print(), and save(). Compare the output immediately after the first call with the saved file and the second call, then trace the property-signature printing path. Done means the first addJsDoc call is reflected by print() as well as save(), with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.