-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[p5.js 2.0 Bug Report]: Typescript declarations missing overloads/optional parameters #7862
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
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you! |
Types are automatically generated from the inline documentation in the codebase, so these overloads or missing optionals will need to be corrected there (this means the documented function signatures are also slightly incorrect.) If anyone is interested in going through the list here (thanks for compiling it!) that would be appreciated! |
I don't mind giving it a try. I'll also look for more discrepancies as the above list is not complete. |
Thanks @SoundOfScooting , I have assign you this one. Thanks for the help :) |
I'm starting work on this and notice some other issues. As mentioned in the issue, TypeScript errors at - ".": "./dist/app.js",
+ ".": {
+ "types": "./types/p5.d.ts",
+ "default": "./dist/app.js"
+ },
- "./core": "./dist/core/main.js",
+ "./core": {
+ "types": "./types/core/main.d.ts",
+ "default": "./dist/core/main.js"
+ }, vscode(ium) also reports these syntax errors which can be made into other issues if necessary.
|
Oh, it appears that I was mistaken that one of the I've looked into it more thoroughly. The documentation comments correctly mark parameters as optional with |
Thanks for narrowing it down @SoundOfScooting! Are you interested in trying to fix the optional handling in that file too? It looks like it is currently trying to be handled here (possibly the broken cases are going through a different code path?): Line 310 in 2606c21
For reference, for the documentation on the website and for FES, it happens here: Lines 64 to 65 in 2606c21
|
I think none of them ended up merged because someone was working on it and we didn't want people to jump the queue, but then they later closed their PR without making revisions. So I think that one is open again to be worked on, I've marked it as Help Wanted and Good First Issue. |
Okay, I've fixed the main issue of optional parameters. Both Organized parameters have a different format than regular ones: Lines 286 to 290 in 2606c21
generateTypeFromTag actually strips OptionalType , so the detection in generateParamDeclaration fails. A simple fix is to change the detection to param.optional || param.type?.type === 'OptionalType' .
|
Uh oh!
There was an error while loading. Please reload this page.
Most appropriate sub-area of p5.js?
p5.js version
v2.0.3
Web browser and version
No response
Operating system
No response
Steps to reproduce this
There are many missing overloads in the generated TypeScript definitions, most of which are functions with runtime optional parameters that are not declared as optional.
Usage of these missing overloads is an error when using
"strict": true
intsconfig.json
.Some examples in
p5.d.ts
(not an exhaustive list):Tested using p5 instance mode.
To actually use the generated types I had to change this part of
p5/package.json
.I'm compiling to an HTML file that can be opened offline with
file://
, but because of CORS the HTML file cannot use JS modules and I must disable the friendly error system.To do this I've used Parcel to bundle the files with settings
"outputFormat": "global", "scopeHoist": false
, but it requires me to comment out a blockif (typeof P5_DEV_BUILD !== 'undefined') {
insidelib/p5.js
(p5.min.js
works fine).This is my current working setup (suggestions welcome):
The text was updated successfully, but these errors were encountered: