-
Notifications
You must be signed in to change notification settings - Fork 21
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
Missing typings #3
Comments
I think this might be fixed already, but I can't check this at the moment. @TeemuKoivisto please try out the typings from SNAPSHOT! |
@Zalastax Hi and thanks for the swift response. I copied the Otherwise yes the constants work and the amp-method is fixed. I'm not sure what is the correct behavior of SoundFile's constructor as it requires a string or any[] as path yet in the examples it had no arguments https://p5js.org/examples/sound-record-save-audio.html and it does work without any arguments. There was also a problem with p5.AudioIn interface which was missing quite a lot properties that I declared locally:
Aaand also since I'm here going off on a rant I noticed that the only way of saving audio is with Regards to my project it is not nearly as ready as I'd like it to be 😅. Looks shabby and is but a curious experiment with pitch detection (that actually is not as good as I thought it would be). |
p5 doesn't use default exports if I reckon correctly. Instead, use: import * as p5 from "p5"; It's great that you're working with the sound part! Regarding APIs, this repo mirrors the documentation of the official repo. If interfaces are missing: go update the documentation (we can figure out what to fix in an issue in this repo)! 😄 Where would you say you are stuck on using p5 and TS (if you are stuck, that is)? |
Sorry for the late reply, I'm on vacation so I'm taking a break kind of from coding. But yeah ups forgot about that syntax. All right that works. Hmm I haven't faced anything too insurmountable yet although the syntax for using p5 is a bit strange. I understand it's quite similar to how d3 works and that with React which I'm using you don't really want to use d3 or p5 through React as in rendering and such (I think?). Would probably make it way too slow. How I figured you should plug-in p5 to your React app is with a React Component -wrapper around a div or something into which p5 canvas is drawn as in react-p5-wrapper. That's kinda unintuitive or at least bit hard to set up. Truth to be told I'm not even 100% how it works. Or how props are passed down to the sketch-function where the p5 magic happens. Then with my canvas it's also a bit peculiar how p5 is used as a local global object to create everything. Singleton pattern is a bit of a throwback to the old JS days.. =) So here for example I have my canvas with some logic about drawing frequencies and current pitch. https://github.com/TeemuKoivisto/pitch-detection/blob/master/src/p5/sketch.ts To my eye it's a bit tangled and I haven't figured out yet how I'm going to break it into parts if it expands. I guess by first moving big methods to their responsive files but yeah having a global object that's used for (almost) everything is a bit cumbersome and impractical. Also binding directly to random p5 lifecycle methods as in my example say I'd enjoy that setting up p5 with TS (and React in that matter) was easy. Currently it's not (even if omitting breaking typings). Using a single function with p5 as a parameter and then binding to it with Hmm that became long and sprawling. Sorry! |
Your project and comments helped me set up examples/webpack. Thanks! |
Hmm yeah types work with the typings from the SNAPSHOT. Just need the p5.sound fixes too and I can throw away my local typings. I'm looking forward to seeing your React-example! So sure you can close this. |
Then I see one actionable thing here: fix the YUIDoc comments for p5.sound! |
I'm getting errors too. But I'm using a reference path in my typescript file. The global.d.ts file comes up with errors. I tried using the ones on the SNAPSHOT branch, but it doesn't recognize the p5 type. |
@K06RA can you try out the new SNAPSHOT definitions? You can download them from SNAPSHOT.zip. |
@TeemuKoivisto I've added a React example now! Feel free to open a new issue, but I'm closing this one since it's a bit messy and I think everything is resolved. |
(copying over from processing/p5.js#3078 — thanks @TeemuKoivisto!)
As the title suggests using p5.js with TypeScript results in compiler throwing errors about missing typings for various constants: Cannot find name 'COLOR_MODE'.. From what I've gathered those constants are defined in p5.global-mode.d.ts yet as I recall I couldn't make it work even by importing global-typings instead of regular p5.d.ts.
I've avoided the issue by mocking p5 with an any-value which is a sorry hack but I didn't want to invest too much time in this. Similar issue was referenced in processing/p5.js#2605
The text was updated successfully, but these errors were encountered: