Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typescript returned instance type #1796

Merged
merged 3 commits into from
May 25, 2020

Conversation

sasensi
Copy link
Contributor

@sasensi sasensi commented Apr 6, 2020

Description

See the related issue for a reproduction case.
The problem is that JSDoc itself doesn't have a way to solve this issue, as shown here: jsdoc/jsdoc#991
So the best workaround (also used by other libraries) seems to be using a custom JSDoc tag that is only understood by the TypeScript definition generator. When this tag is detected, the return type is replaced by TypeScript this type which perfectly solves this issue (it is actually done for this specific use case).

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the JSHint rules (npm run jshint passes)

Adds a new custom JSDoc tag allowing typescript definition to use `this` type as
a return type for inherited methods.

Closes paperjs#1795
Copy link
Member

@lehni lehni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I would suggest we call the tag simply @chainable though, as it's not specific to TS anyway? (See: jsdoc/jsdoc#991 (comment))

@sasensi
Copy link
Contributor Author

sasensi commented May 24, 2020

This is great! I would suggest we call the tag simply @chainable though, as it's not specific to TS anyway? (See: jsdoc/jsdoc#991 (comment))

No, this was a totally made up name, so we can totally change it (which I just did in the last commit).

@lehni
Copy link
Member

lehni commented May 25, 2020

Great, thanks @sasensi!

@lehni lehni merged commit 4c2254f into paperjs:develop May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

path.clone() doesn't have the right return type in TypeScript
2 participants