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

Typescript declaration files script #7465

Open
wants to merge 2 commits into
base: dev-2.0
Choose a base branch
from

Conversation

diyaayay
Copy link
Contributor

This is based off of #6777 and #6972. WIP.
Maybe an AST based approach could be added to the current script. This still needs to handle a few cases, such as static methods.

Changes:

Screenshots of the change:

PR Checklist

@diyaayay diyaayay changed the title added boilerplate script Typescript declaration files script Jan 12, 2025
@diyaayay diyaayay force-pushed the typescript-declarations branch from 0f35005 to 16149c1 Compare January 14, 2025 07:02
@diyaayay diyaayay force-pushed the typescript-declarations branch from 2face78 to 35cb018 Compare January 17, 2025 20:52
@diyaayay diyaayay marked this pull request as ready for review January 17, 2025 20:53
@diyaayay
Copy link
Contributor Author

I think this still needs work, the format of the output files, and cases to be handled. But, @davepagurek Do you think this would be the correct approach to bypass tsc and generate .d.ts files.

@davepagurek
Copy link
Contributor

I think that's probably the best way forward, since it seemed pretty hard to get tsc to understand how we're adding to p5 classes dynamically. Looking good so far!

function generateTypeFromTag(param) {
if (!param || !param.type) return 'any';

switch (param.type.type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A more complex case you might want to try with is paletteLerp, which has an array of tuples:

* @method paletteLerp
* @param {[p5.Color, Number][]} colors_stops color stops to interpolate from

Ideally that out output basically back out to its original format, or possibly Array<[p5.Color, number]>

@diyaayay diyaayay force-pushed the typescript-declarations branch 2 times, most recently from 19c5fba to 35cb018 Compare January 19, 2025 07:14
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.

2 participants