Stéphane
How to use a class name as a qualifier for an enum ?
Thanks a lot for your answer. That's the conclusion I got by looking through diverse stackoverflow threads, but it's good to see I didn't overlook something. And yeah I tried to get something closer to C++ where an enum can be nested in a class so I could have just one export embedding all the class features. The
import * as
trick is ok I guess.
And yeah I didn't even think about looking at the std lib haha4 replies
API architecture for generic callback
I used the npm version a few years ago for a digital arts project where many people could connect to my computer via their phone to control music in a live context, all at the same time, using websockets. It was pretty fun
30 replies
API architecture for generic callback
Thanks 🙂 it's not really an app, it's meant to be used server side. It's a port of this npm package : https://github.com/justinlatimer/node-midi
The idea behind it (for my use case at least) is to create remote midi controllers for basically anything 🙂
30 replies
API architecture for generic callback
Hi again 🙂
Thanks again for the help @ndh3193 I implemented something very similar to what you shared (you can check here : https://github.com/stfufane/deno-midi/blob/main/lib/events.ts for the types and https://github.com/stfufane/deno-midi/blob/main/lib/midi.ts#L258 for on/off/emit)
Now I tried some things to take it a bit further, but with no success, and wonder if you'd have any extra knowledge on how to achieve this (maybe it's juste not possible...)
Basically, with this API, the user can do this :
which is nice, but I'd like a way to automatically infer the type of the message variable in the callback, and using generics I just did not find how to do that.
My idea is something like this :
So that the user would be able to do :
I think it'd make a clearer usage with autocompletion and everything running smoothly. But T is a type, not a value,
typeof T
and T.prototype.constructor
don't seem to work either...30 replies
API architecture for generic callback
Cool suggestion. I'm doing that and now encounter a weird issue.
I created this interface (+ the alternative for raw messages)
and used it like this :
But the linter is not happy about it :
Type '{ message: Message<MessageData>; deltaTime: number; }' is not assignable to type 'MidiMessageEvent'. Object literal may only specify known properties, and 'message' does not exist in type 'MidiMessageEvent'.deno-ts(2322)despite having the propriety 🤷♂️ If I do this instead, it's ok... But I still get an error when trying to add an event listener :
30 replies
What is the difference between JS Map and JS Object?
There's a good explanation on the MDN doc here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#objects_vs._maps
but basically the Map offers a more secure API to manipulate your data than the object does
4 replies