diff --git a/ui/src/components/file/QFile.json b/ui/src/components/file/QFile.json index 2ca8fe0f9bb..cbbfaa8c042 100644 --- a/ui/src/components/file/QFile.json +++ b/ui/src/components/file/QFile.json @@ -168,6 +168,7 @@ "desc": "DEPRECATED; Access 'nativeEl' directly; Gets the native input DOM Element", "returns": { "type": "Element", + "tsType": "QFileNativeElement", "desc": "The underlying native input DOM Element" } } @@ -176,6 +177,7 @@ "computedProps": { "nativeEl": { "type": "Element", + "tsType": "QFileNativeElement", "desc": "The native input DOM Element", "addedIn": "v2.10.1" } diff --git a/ui/src/components/input/QInput.json b/ui/src/components/input/QInput.json index d22add42c43..9f4d4634820 100644 --- a/ui/src/components/input/QInput.json +++ b/ui/src/components/input/QInput.json @@ -118,6 +118,7 @@ "desc": "DEPRECATED; Access 'nativeEl' directly instead; Get the native input/textarea DOM Element", "returns": { "type": "Element", + "tsType": "QInputNativeElement", "desc": "The underlying native input/textarea DOM Element" } } @@ -126,6 +127,7 @@ "computedProps": { "nativeEl": { "type": "Element", + "tsType": "QInputNativeElement", "desc": "The native input/textarea DOM Element", "addedIn": "v2.10.1" } diff --git a/ui/types/api.d.ts b/ui/types/api.d.ts index 93e8ffcaf66..61947faa64a 100644 --- a/ui/types/api.d.ts +++ b/ui/types/api.d.ts @@ -2,6 +2,7 @@ export * from "./api/vue-prop-types"; export * from "./api/cookies"; export * from "./api/dialog"; export * from "./api/qfile"; +export * from "./api/qinput"; export * from "./api/qselect"; export * from "./api/qtable"; export * from "./api/qtree"; diff --git a/ui/types/api/qfile.d.ts b/ui/types/api/qfile.d.ts index d70d600e6ae..2524b38d833 100644 --- a/ui/types/api/qfile.d.ts +++ b/ui/types/api/qfile.d.ts @@ -6,3 +6,8 @@ export interface QRejectedEntry { | "filter"; file: File; } + +export type QFileNativeElement = Omit< + Omit & { files: FileList }, + "type" +> & { type: "file" }; diff --git a/ui/types/api/qinput.d.ts b/ui/types/api/qinput.d.ts new file mode 100644 index 00000000000..b18f201fe75 --- /dev/null +++ b/ui/types/api/qinput.d.ts @@ -0,0 +1,27 @@ +// Error on "quasar" import shown in IDE is normal, as we only have Components/Directives/Plugins types after the build step +// The import will work correctly at runtime +import { QInputProps } from "quasar"; + +type QInputType = NonNullable; + +type WithKnownType< + TElement extends HTMLInputElement | HTMLTextAreaElement, + TType extends QInputType +> = Omit & { type: TType }; + +/** + * @example + * ```ts + * QInputNativeElement // HTMLInputElement | HTMLTextAreaElement + * QInputNativeElement<"textarea"> // HTMLTextAreaElement + * QInputNativeElement<"text"> // Omit & { type: "text" } + * QInputNativeElement<"text" | "number"> // Omit & { type: "text" | "number" } + * QInputNativeElement<"text" | "textarea"> // (Omit & { type: "text" }) | HTMLTextAreaElement + * ``` + */ +export type QInputNativeElement = + T extends "textarea" + ? WithKnownType + : Omit, "files"> & { + files: T extends "file" ? FileList : null; + };