diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 6dda5c02e..0df481561 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -17341,7 +17341,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection) */ - selectionDirection: "forward" | "backward" | "none" | null; + selectionDirection: SelectionDirection | null; /** * The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position. * @@ -17470,7 +17470,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange) */ - setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void; + setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void; /** * The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element. * @@ -42478,6 +42478,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext; type ReportList = Report[]; type RequestInfo = Request | string; +type SelectionDirection = "forward" | "backward" | "none"; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; type TimerHandler = string | Function; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index c4f489707..d10659836 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -17323,7 +17323,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection) */ - selectionDirection: "forward" | "backward" | "none" | null; + selectionDirection: SelectionDirection | null; /** * The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position. * @@ -17452,7 +17452,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange) */ - setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void; + setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void; /** * The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element. * @@ -42452,6 +42452,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext; type ReportList = Report[]; type RequestInfo = Request | string; +type SelectionDirection = "forward" | "backward" | "none"; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; type TimerHandler = string | Function; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index cdf8123a8..2e5b922e6 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -17338,7 +17338,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection) */ - selectionDirection: "forward" | "backward" | "none" | null; + selectionDirection: SelectionDirection | null; /** * The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position. * @@ -17467,7 +17467,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange) */ - setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void; + setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void; /** * The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element. * @@ -42475,6 +42475,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext; type ReportList = Report[]; type RequestInfo = Request | string; +type SelectionDirection = "forward" | "backward" | "none"; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; type TimerHandler = string | Function; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index e2f589ea4..3773a12d8 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -17338,7 +17338,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/selectionDirection) */ - selectionDirection: "forward" | "backward" | "none" | null; + selectionDirection: SelectionDirection | null; /** * The **`selectionEnd`** property of the HTMLInputElement interface is a number that represents the end index of the selected text. That is, it represents the index of the character immediately following the selection. Likewise, when there is no selection, this returns the offset of the character immediately following the current text input cursor position. * @@ -17467,7 +17467,7 @@ interface HTMLInputElement extends HTMLElement, PopoverTargetAttributes { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setSelectionRange) */ - setSelectionRange(start: number | null, end: number | null, direction?: "forward" | "backward" | "none"): void; + setSelectionRange(start: number | null, end: number | null, direction?: SelectionDirection): void; /** * The **`HTMLInputElement.showPicker()`** method displays the browser picker for an input element. * @@ -42475,6 +42475,7 @@ type ReadableStreamReader = ReadableStreamDefaultReader | ReadableStreamBY type RenderingContext = CanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext; type ReportList = Report[]; type RequestInfo = Request | string; +type SelectionDirection = "forward" | "backward" | "none"; type TexImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas | VideoFrame; type TimerHandler = string | Function; type Transferable = OffscreenCanvas | ImageBitmap | MessagePort | MediaSourceHandle | ReadableStream | WritableStream | TransformStream | AudioData | VideoFrame | RTCDataChannel | ArrayBuffer; diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index a05a375b9..9260d0783 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -301,15 +301,6 @@ } } }, - "HTMLInputElement": { - "properties": { - "property": { - "labels": { - "overrideType": "NodeListOf" - } - } - } - }, "RuntimeError": { "name": "RuntimeError", "extends": "Error", diff --git a/inputfiles/knownTypes.json b/inputfiles/knownTypes.json index df1b8cda5..a16e077ba 100644 --- a/inputfiles/knownTypes.json +++ b/inputfiles/knownTypes.json @@ -14,7 +14,6 @@ "AutoFillContactField", "AutoFillField", "AutoFillCredentialField", - "AutoFill", "BigInteger", "ClientQueryOptions", "ClientTypes", diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index af2258aa5..1e86d1786 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1445,48 +1445,6 @@ } } }, - "HTMLInputElement": { - "properties": { - "property": { - "autocomplete": { - "name": "autocomplete", - "overrideType": "AutoFill" - }, - "selectionDirection": { - "name": "selectionDirection", - "overrideType": "\"forward\" | \"backward\" | \"none\"" - }, - "valueAsDate": { - "name": "valueAsDate", - "overrideType": "Date" - } - } - }, - "methods": { - "method": { - "setSelectionRange": { - "signature": { - "0": { - "param": [ - { - "name": "start", - "nullable": true - }, - { - "name": "end", - "nullable": true - }, - { - "name": "direction", - "overrideType": "\"forward\" | \"backward\" | \"none\"" - } - ] - } - } - } - } - } - }, "MouseEvent": { "methods": { "method": { diff --git a/inputfiles/patches/html.kdl b/inputfiles/patches/html.kdl index edb9f0ed5..00b0380a4 100644 --- a/inputfiles/patches/html.kdl +++ b/inputfiles/patches/html.kdl @@ -47,6 +47,30 @@ interface HTMLImageElement { property loading overrideType=#""eager" | "lazy""# } +interface HTMLInputElement { + property labels { + type NodeListOf { + type HTMLLabelElement + } + } + property autocomplete type=AutoFill + property valueAsDate type=Date + property selectionDirection type=SelectionDirection + method setSelectionRange signatureIndex=0 { + // nullable types because we want to allow passing selectionStart/End properties, which are nullable. + // See also https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/878. + param start { + type nullable=#true + } + param end { + type nullable=#true + } + param direction type=SelectionDirection + } +} + +typedef SelectionDirection overrideType=#""forward" | "backward" | "none""# + dictionary StructuredSerializeOptions { member transfer { type { diff --git a/src/build/patches.ts b/src/build/patches.ts index 292cbb3da..f2484e436 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -307,6 +307,7 @@ function handleProperty(child: Node): DeepPartial { function handleParam(node: Node) { const name = string(node.values[0]); let additionalTypes: string[] | undefined; + const typeNodes: Node[] = []; for (const child of node.children) { switch (child.name) { @@ -317,6 +318,10 @@ function handleParam(node: Node) { additionalTypes = child.values.map(string); break; } + case "type": { + typeNodes.push(child); + break; + } default: throw new Error(`Unexpected child "${child.name}" in param "${name}"`); } @@ -324,7 +329,7 @@ function handleParam(node: Node) { return { name, - ...optionalMember("type", "string", node.properties?.type), + ...handleTyped(typeNodes, node.properties?.type), ...optionalMember("overrideType", "string", node.properties?.overrideType), additionalTypes, }; @@ -343,7 +348,7 @@ function handleMethodAndConstructor( // Collect all type nodes into an array const typeNodes: Node[] = []; - const params: Partial[] = []; + const params: DeepPartial[] = []; for (const c of child.children) { switch (c.name) { @@ -452,6 +457,7 @@ function handleTypedef(node: Node): DeepPartial { "string", node.properties?.legacyNamespace, ), + ...optionalMember("overrideType", "string", node.properties?.overrideType), }; }