diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 8c7d9849f..27ae7ec0d 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1310,26 +1310,6 @@ } } }, - "IDBRequest": { - "properties": { - "property": { - "source": { - "name": "source", - "nullable": false - }, - "result": { - "name": "result", - "overrideType": "T" - } - } - }, - "typeParameters": [ - { - "name": "T", - "default": "any" - } - ] - }, "ImageBitmapRenderingContext": { "properties": { "property": { diff --git a/inputfiles/patches/indexeddb.kdl b/inputfiles/patches/indexeddb.kdl new file mode 100644 index 000000000..b11fc6ab4 --- /dev/null +++ b/inputfiles/patches/indexeddb.kdl @@ -0,0 +1,7 @@ +interface IDBRequest { + typeParameters T default=any + property source { + type nullable=#false + } + property result overrideType=T +} diff --git a/src/build/patches.ts b/src/build/patches.ts index fe79fcb3e..26368e585 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -48,16 +48,15 @@ function string(arg: unknown): string { return arg; } -function handleTyped(type: Node): Typed { +function handleTyped(type: Node): DeepPartial { const isTyped = type.name == "type"; if (!isTyped) { throw new Error("Expected a type node"); } - const name = string(type.values[0]); const subType = type.children.length > 0 ? handleTyped(type.children[0]) : undefined; return { - type: name, + ...optionalMember("type", "string", type.values[0]), subtype: subType, ...optionalMember("nullable", "boolean", type.properties?.nullable), }; @@ -167,8 +166,9 @@ function handleMixinAndInterfaces( const name = string(node.properties?.name || node.values[0]); const event: Event[] = []; - const property: Record> = {}; + const property: Record> = {}; let method: Record> = {}; + let typeParameters = {}; for (const child of node.children) { switch (child.name) { @@ -188,12 +188,17 @@ function handleMixinAndInterfaces( }); break; } + case "typeParameters": { + typeParameters = handleTypeParameters(child); + break; + } default: throw new Error(`Unknown node name: ${child.name}`); } } const interfaceObject = type === "interface" && { + ...typeParameters, ...optionalMember("exposed", "string", node.properties?.exposed), ...optionalMember("deprecated", "string", node.properties?.deprecated), ...optionalMember( @@ -240,7 +245,7 @@ function handleEvent(child: Node): Event { * Handles a child node of type "property" and adds it to the property object. * @param child The child node to handle. */ -function handleProperty(child: Node): Partial { +function handleProperty(child: Node): DeepPartial { let typeNode: Node | undefined; for (const c of child.children) { if (c.name === "type") {