Skip to content

refactor: split type definition to multiple files, define all framework types inside the Q5 class using build script #137

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

xynydev
Copy link

@xynydev xynydev commented Aug 17, 2025

Fixes: #132

@xynydev
Copy link
Author

xynydev commented Aug 17, 2025

My first draft of this was just naively inserting all the type definitions from framework.d.ts into instance-mode.d.ts, but I discovered that the type definitions inside a class declaration use a different format. Then I discovered that typeof xxx gives the type of a given declaration in global scope, and each declaration can be added into the class in instance-mode.d.ts as such. After that, the only problem left was to find the names of all declarations inside framework.d.ts for the generation of the type 'imports'. I asked AI about the problem, and received a fully functional function which worked well in my testing.

I tested this change by copying the new .d.ts files into the correct places inside the node_modules of a project I am working on. I am not sure of how I could test if this change works in the NPM package release as well.

All suggestions / change requests welcome. I am not quite sure, for example, if the naming of the type files matches the official terminology, so if you want those to be changed, that's fine.

@quinton-ashley
Copy link
Member

I can't merge because /q5.d.ts is required by /learn/docs.js to generate the Learn page at https://q5js.org/learn

All files in /types will be loaded by VSCode, so template/build files should go in a folder with another name, perhaps types_build.

Also use tabs instead of spaces in /package.json to minimize changed lines.

@xynydev
Copy link
Author

xynydev commented Aug 18, 2025

Thanks for the review, I'll resolve these next time I'm at my desktop.

I can't merge because /q5.d.ts is required by /learn/docs.js to generate the Learn page at https://q5js.org/learn

That's actually still there, it just references the type files with /// . But yeah, docs.js does not seem to understand that right now. Should it be changed to just read ./types/framework.d.ts instead? That's the simplest solution I can think of.

All files in /types will be loaded by VSCode, so template/build files should go in a folder with another name, perhaps types_build.

Good catch, will do.

Also use tabs instead of spaces in /package.json to minimize changed lines.

Yeah, that's either my editor or bun i doing some automatic formatting for some reason, I'll try to fix that. Annoying...

@quinton-ashley
Copy link
Member

quinton-ashley commented Aug 18, 2025

That'd almost work but framework.d.ts is missing these:

https://q5js.org/learn/#Q5
https://q5js.org/learn/#Q5.WebGPU

Perhaps you could build one typescript file /q5.d.ts and don't make a types folder. Then adjust docs.js to stop before the dupped instance props.

@xynydev
Copy link
Author

xynydev commented Aug 20, 2025

Perhaps you could build one typescript file /q5.d.ts and don't make a types folder. Then adjust docs.js to stop before the dupped instance props.

That would work, I guess. But maybe it would be less work on the docs.js side to just read both framework.d.ts and instace-mode-template.d.ts instead of making it stop before the duplicated props?

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.

Missing types when running in instance mode
2 participants