TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

WebMIDI

Open sy-filis opened this issue 1 year ago • 1 comments
trafficstars

Hi there,

Could someone please address an issue with the WebMIDI API types lib.dom.d.ts:14856-15024?

I believe that MIDIInputMap should extend ReadOnlyMap<MIDIInput["id"], MIDIInput> (MDN) and that the forEach method could be removed as part of ReadOnlyMap interface (es2015.iterable.d.ts:119, es2015.collection.d.ts:37). The same situation applies to MIDIOutputMap (MDN).

The second issue concerns constructors for MIDIAccess, MIDIInputMap, MIDIOutputMap, MIDIPort, MIDIInput and MIDIOutput. When attempting to instantiate any of these, I encounter an Uncaught TypeError: Illegal constructor error, although TypeScript indicates it should be permissible.

Thank you.

sy-filis avatar May 13 '24 08:05 sy-filis

The reason it's done with forEach is because es5 doesn't support Map. For target: ES2015+ you should automatically get ReadonlyMap:

https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/4d34d6d2aa813555adab859d28d2389672c28474/baselines/dom.iterable.generated.d.ts#L171-L172

Or you can give "lib": ["dom", "dom.iterable"].

saschanaz avatar Jun 25 '24 23:06 saschanaz

Hello @saschanaz, I believe this can be closed since it was a question rather than an actual issue.

Bashamega avatar Mar 30 '25 13:03 Bashamega

Yup.

@github-actions close

saschanaz avatar Mar 30 '25 13:03 saschanaz

Closing because @saschanaz is one of the code-owners of this repository.

github-actions[bot] avatar Mar 30 '25 13:03 github-actions[bot]

Hi @saschanaz,

I forgot to write, sorry. I have to explicitly give "lib": ["dom", "dom.iterable"] to have these methods included, although the target is ES2015+.

sy-filis avatar Mar 30 '25 14:03 sy-filis

In that case that may be TypeScript bug, unless you already assigned other libs in the field. If you assigned any value in lib then it needs dom and dom.iterable together.

saschanaz avatar Mar 30 '25 14:03 saschanaz

(The generator can't do much, if it's still an issue please file a bug in TS repo)

saschanaz avatar Mar 30 '25 14:03 saschanaz

In that case that may be TypeScript bug, unless you already assigned other libs in the field. If you assigned any value in lib then it needs dom and dom.iterable together.

Ouu, I didn't know that the other libs field has to be empty not to include others manually... After I tested it out, everything is ok.

Thx for help, @saschanaz.

sy-filis avatar Mar 30 '25 18:03 sy-filis