From 7e53c435c36c43c63b33db6621061b351f199037 Mon Sep 17 00:00:00 2001 From: ajuner <53512912+ajuner@users.noreply.github.com> Date: Sat, 7 Nov 2020 22:39:18 +0800 Subject: [PATCH] chore: declare input type (#3130) --- components/input/Input.tsx | 20 ++++++++++---------- components/input/Password.tsx | 4 ++-- components/input/ResizableTextArea.tsx | 2 +- components/input/Search.tsx | 10 +++++----- components/input/TextArea.tsx | 10 +++++----- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/components/input/Input.tsx b/components/input/Input.tsx index 042bbd0e2..2bf02573e 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -7,16 +7,16 @@ import { hasProp, getComponent, getOptionProps } from '../_util/props-util'; import { defaultConfigProvider } from '../config-provider'; import ClearableLabeledInput from './ClearableLabeledInput'; -export function fixControlledValue(value) { +export function fixControlledValue(value: string | number) { if (typeof value === 'undefined' || value === null) { return ''; } return value; } -export function resolveOnChange(target, e, onChange) { +export function resolveOnChange(target: HTMLInputElement, e: Event, onChange?: Function) { if (onChange) { - const event = e; + const event = e as any; if (e.type === 'click') { // click clear icon //event = Object.create(e); @@ -40,7 +40,7 @@ export function resolveOnChange(target, e, onChange) { } } -export function getInputClassName(prefixCls, size, disabled) { +export function getInputClassName(prefixCls: string, size: string, disabled: boolean) { return classNames(prefixCls, { [`${prefixCls}-sm`]: size === 'small', [`${prefixCls}-lg`]: size === 'large', @@ -91,12 +91,12 @@ export default defineComponent({ } }, methods: { - handleInputFocus(e) { + handleInputFocus(e: Event) { this.isFocused = true; this.onFocus && this.onFocus(e); }, - handleInputBlur(e) { + handleInputBlur(e: Event) { this.isFocused = false; this.onBlur && this.onBlur(e); }, @@ -112,15 +112,15 @@ export default defineComponent({ this.input.select(); }, - saveClearableInput(input: any) { + saveClearableInput(input: HTMLInputElement) { this.clearableInput = input; }, - saveInput(input: any) { + saveInput(input: HTMLInputElement) { this.input = input; }, - setValue(value: any, callback?: Function) { + setValue(value: string | number, callback?: Function) { if (this.stateValue === value) { return; } @@ -134,7 +134,7 @@ export default defineComponent({ }); }, triggerChange(e: Event) { - this.$emit('update:value', (e.target as any).value); + this.$emit('update:value', (e.target as HTMLInputElement).value); this.$emit('change', e); this.$emit('input', e); }, diff --git a/components/input/Password.tsx b/components/input/Password.tsx index b4cf04fea..9556f1c8e 100644 --- a/components/input/Password.tsx +++ b/components/input/Password.tsx @@ -57,12 +57,12 @@ export default defineComponent({ const iconTrigger = ActionMap[action] || ''; const iconProps = { [iconTrigger]: this.onVisibleChange, - onMousedown: e => { + onMousedown: (e: Event) => { // Prevent focused state lost // https://github.com/ant-design/ant-design/issues/15173 e.preventDefault(); }, - onMouseup: e => { + onMouseup: (e: Event) => { // Prevent focused state lost // https://github.com/ant-design/ant-design/pull/23633/files e.preventDefault(); diff --git a/components/input/ResizableTextArea.tsx b/components/input/ResizableTextArea.tsx index 734254397..1e1c6c2c1 100644 --- a/components/input/ResizableTextArea.tsx +++ b/components/input/ResizableTextArea.tsx @@ -61,7 +61,7 @@ const ResizableTextArea = defineComponent({ }, }, methods: { - saveTextArea(textArea: any) { + saveTextArea(textArea: HTMLTextAreaElement) { this.textArea = textArea; }, handleResize(size: any) { diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 7bbd333bc..0d8985485 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -28,17 +28,17 @@ export default defineComponent({ }; }, methods: { - saveInput(node: any) { + saveInput(node: HTMLInputElement) { this.input = node; }, - handleChange(e) { + handleChange(e: Event) { if (e && e.target && e.type === 'click') { - this.$emit('search', e.target.value, e); + this.$emit('search', (e.target as HTMLInputElement).value, e); } - this.$emit('update:value', e.target.value); + this.$emit('update:value', (e.target as HTMLInputElement).value); this.$emit('change', e); }, - handleSearch(e) { + handleSearch(e: Event) { if (this.loading || this.disabled) { return; } diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index e407927d7..671a8fa27 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -35,7 +35,7 @@ export default defineComponent({ }; }, watch: { - value(val) { + value(val: string) { this.stateValue = val; }, }, @@ -49,7 +49,7 @@ export default defineComponent({ }); }, methods: { - setValue(value: any, callback?: Function) { + setValue(value: string, callback?: Function) { if (!hasProp(this, 'value')) { this.stateValue = value; } else { @@ -74,7 +74,7 @@ export default defineComponent({ const { value, composing, isComposing } = e.target as any; if (((isComposing || composing) && this.lazy) || this.stateValue === value) return; - this.setValue((e.target as any).value, () => { + this.setValue((e.target as HTMLTextAreaElement).value, () => { this.resizableTextArea.resizeTextarea(); }); resolveOnChange(this.resizableTextArea.textArea, e, this.triggerChange); @@ -91,7 +91,7 @@ export default defineComponent({ this.resizableTextArea = resizableTextArea; }, - saveClearableInput(clearableInput: any) { + saveClearableInput(clearableInput: HTMLTextAreaElement) { this.clearableInput = clearableInput; }, handleReset(e: Event) { @@ -124,7 +124,7 @@ export default defineComponent({ const { style, class: customClass } = this.$attrs; const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('input', customizePrefixCls); - let value = fixControlledValue(stateValue); + let value = fixControlledValue(stateValue) as string; // Max length value const hasMaxlength = Number(maxlength) > 0; value = hasMaxlength ? value.slice(0, maxlength) : value;