djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.53k stars 115 forks source link

Impossible to build a TypeScript project with WebMIDI. #274

Closed antt0n closed 1 year ago

antt0n commented 2 years ago

Description Impossible to build a TypeScript project with WebMIDI.

Environment: Windows 11 64. Node 17.8.0 Dependencies :

    "@types/jest": "~27.5",
    "@types/node": "~16",
    "@typescript-eslint/eslint-plugin": "~5.26",
    "@typescript-eslint/parser": "~5.26",
    "eslint": "~8.16",
    "eslint-config-prettier": "~8.5",
    "eslint-plugin-jest": "~26.2",
    "jest": "~28.1",
    "prettier": "~2.6",
    "rimraf": "~3.0",
    "ts-jest": "~28.0",
    "tsutils": "~3.21",
    "typescript": "~4.7"

Errors


node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:41:32 - error TS2304: Cannot find name 'EventTarget'.

41   interface MIDIAccess extends EventTarget {
                                  ~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:61:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

61       options?: boolean | AddEventListenerOptions,
                             ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:65:17 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

65       listener: EventListenerOrEventListenerObject,
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:66:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

66       options?: boolean | AddEventListenerOptions,
                             ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:82:30 - error TS2304: Cannot find name 'EventTarget'.

82   interface MIDIPort extends EventTarget {
                                ~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:129:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

129       options?: boolean | AddEventListenerOptions,
                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:133:17 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

133       listener: EventListenerOrEventListenerObject,
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:134:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

134       options?: boolean | AddEventListenerOptions,
                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:171:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

171       options?: boolean | AddEventListenerOptions,
                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:176:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

176       options?: boolean | AddEventListenerOptions,
                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:180:17 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

180       listener: EventListenerOrEventListenerObject,
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:181:27 - error TS2304: Cannot find name 'AddEventListenerOptions'.

181       options?: boolean | AddEventListenerOptions,
                              ~~~~~~~~~~~~~~~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:218:42 - error TS2304: Cannot find name 'EventInit'.

218   interface MIDIMessageEventInit extends EventInit {
                                             ~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:237:45 - error TS2304: Cannot find name 'EventInit'.

237   interface MIDIConnectionEventInit extends EventInit {
                                                ~~~~~~~~~

node_modules/webmidi/dist/cjs/webmidi.cjs.d.ts:6078:14 - error TS2304: Cannot find name 'DOMHighResTimeStamp'.

6078   timestamp: DOMHighResTimeStamp;
                  ~~~~~~~~~~~~~~~~~~~

src/main.ts:1:19 - error TS6133: 'WebMidiEventMap' is declared but its value is never read.

1 import { WebMidi, WebMidiEventMap } from "webmidi";
                    ~~~~~~~~~~~~~~~

src/main.ts:5:11 - error TS6133: 'isEnabled' is declared but its value is never read.```
djipco commented 2 years ago

I'm not sure why you are having these issues. Can you perhaps try a bare example so we can narrow down the problem?

djipco commented 1 year ago

Did you resolve this issue? If not, can you submit a minimal project example that triggers the problem?

braebo commented 1 year ago

This looks like a bad tsconfig problem.

The errors referencing EventTarget and AddEventListener are likely because you need to add DOM to your tsconfig.json:

  "compilerOptions": {
    "lib": ["ESNext", "DOM", "DOM.Iterable"],

It's also possible that your tsconfig is missing the field that tells it to exclude your node_modules folder from the typechecking process:

  "exclude": [
    "node_modules/**",
     //...
djipco commented 1 year ago

Considering @FractalHQ's suggestion and the fact that it has been tagged as "info needed" since June, I will close this issue. Feel free to re-open if the problem persists. You can also post your questions in the discussion's Q&A section.