Closed glend1 closed 2 years ago
I just tried the code below in Node.js and I'm not getting any errors with v3.0.10:
const {WebMidi} = require("webmidi");
WebMidi.addListener("connected", e => console.log(e.target.name));
WebMidi.enable();
Can you provide a little more info about the environment where you get that error?
I am using Next.js which doesn't like using require
so I converted your code to an import
(you are able to bypass as shown in the following code snippet with export {}
)
//import {WebMidi} from "webmidi";
const {WebMidi} = require("webmidi");
WebMidi.addListener("connected", e => console.log(e.target.name));
WebMidi.enable();
export{}
however, with require
I notice that e
is any
.
There must be something different in your environment because it works for me. Your code example ran fine in a demo Next.js project. I tried with require
and import
and both worked fine.
Hold on... I think I found the issue. Let me get back to you.
I took a deeper look at events and concluded that all events that are triggered by a port (Input
or Output
) needed their own type definitions for TypeScript. So, I have added a PortEvent
type that extends the basic Event
type. The PortEvent
type has a port
property that points to the Input
of Output
port.
So, in your case, you should be able to use e.port.name
just like before.
This will also help when adding a listener to an InputChannel
. In this case, e.port
will point to the Input
object while e.target
will point to the InputChannel
object.
This change is available right now in version 3.0.11.
thought i had a issue open for this, but i can't seem to find it so im reposting. sorry if im just being blind.
when I do the following
i get the following typescript error