From 05c702838dbb1342e932b2a378754114a6017376 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Tue, 21 Nov 2017 19:51:31 +0800 Subject: [PATCH] Fix implicit any error for Input --- components/input-number/index.tsx | 2 +- components/input/Input.tsx | 10 +++++----- components/input/Search.tsx | 2 +- components/input/TextArea.tsx | 12 ++++++------ components/input/calculateNodeHeight.tsx | 23 +++++++++++++++-------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx index 2f3a6b846d..3fd089052c 100644 --- a/components/input-number/index.tsx +++ b/components/input-number/index.tsx @@ -38,7 +38,7 @@ export default class InputNumber extends React.Component [`${this.props.prefixCls}-sm`]: size === 'small', }, className); - return this.inputNumberRef = c} className={inputNumberClass} {...others} />; + return this.inputNumberRef = c} className={inputNumberClass} {...others} />; } focus() { diff --git a/components/input/Input.tsx b/components/input/Input.tsx index 3ab013ab47..a1aaef41c8 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -6,7 +6,7 @@ import Group from './Group'; import Search from './Search'; import TextArea from './TextArea'; -function fixControlledValue(value) { +function fixControlledValue(value: undefined | null | string) { if (typeof value === 'undefined' || value === null) { return ''; } @@ -82,7 +82,7 @@ export default class Input extends React.Component { input: HTMLInputElement; - handleKeyDown = (e) => { + handleKeyDown = (e: React.KeyboardEvent) => { const { onPressEnter, onKeyDown } = this.props; if (e.keyCode === 13 && onPressEnter) { onPressEnter(e); @@ -109,11 +109,11 @@ export default class Input extends React.Component { }); } - saveInput = (node) => { + saveInput = (node: HTMLInputElement) => { this.input = node; } - renderLabeledInput(children) { + renderLabeledInput(children: React.ReactElement) { const props = this.props; // Not wrap when there is not addons if ((!props.addonBefore && !props.addonAfter)) { @@ -163,7 +163,7 @@ export default class Input extends React.Component { ); } - renderLabeledIcon(children) { + renderLabeledIcon(children: React.ReactElement) { const { props } = this; if (!('prefix' in props || 'suffix' in props)) { return children; diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 7b2b61fbb6..4b5492542f 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -27,7 +27,7 @@ export default class Search extends React.Component { this.input.focus(); } - saveInput = (node) => { + saveInput = (node: Input) => { this.input = node; } diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index 1acd67e758..ce31fee5a7 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -4,14 +4,14 @@ import classNames from 'classnames'; import { AbstractInputProps } from './Input'; import calculateNodeHeight from './calculateNodeHeight'; -function onNextFrame(cb) { +function onNextFrame(cb: () => void) { if (window.requestAnimationFrame) { return window.requestAnimationFrame(cb); } return window.setTimeout(cb, 1); } -function clearNextFrameAction(nextFrameId) { +function clearNextFrameAction(nextFrameId: number) { if (window.cancelAnimationFrame) { window.cancelAnimationFrame(nextFrameId); } else { @@ -52,7 +52,7 @@ export default class TextArea extends React.Component { + handleTextareaChange = (e: React.ChangeEvent) => { if (!('value' in this.props)) { this.resizeTextarea(); } @@ -98,7 +98,7 @@ export default class TextArea extends React.Component { + handleKeyDown = (e: React.KeyboardEvent) => { const { onPressEnter, onKeyDown } = this.props; if (e.keyCode === 13 && onPressEnter) { onPressEnter(e); @@ -108,7 +108,7 @@ export default class TextArea extends React.Component { + saveTextAreaRef = (textArea: HTMLTextAreaElement) => { this.textAreaRef = textArea; } diff --git a/components/input/calculateNodeHeight.tsx b/components/input/calculateNodeHeight.tsx index 299df2ccea..35d285c9a0 100644 --- a/components/input/calculateNodeHeight.tsx +++ b/components/input/calculateNodeHeight.tsx @@ -34,15 +34,22 @@ const SIZING_STYLE = [ 'box-sizing', ]; -let computedStyleCache = {}; -let hiddenTextarea; +export interface NodeType { + sizingStyle: string; + paddingSize: number; + borderSize: number; + boxSizing: string; +} + +let computedStyleCache: {[key: string]: NodeType} = {}; +let hiddenTextarea: HTMLTextAreaElement; -function calculateNodeStyling(node, useCache = false) { +function calculateNodeStyling(node: HTMLElement, useCache = false) { const nodeRef = ( node.getAttribute('id') || node.getAttribute('data-reactid') || node.getAttribute('name') - ); + ) as string; if (useCache && computedStyleCache[nodeRef]) { return computedStyleCache[nodeRef]; @@ -70,7 +77,7 @@ function calculateNodeStyling(node, useCache = false) { .map(name => `${name}:${style.getPropertyValue(name)}`) .join(';'); - const nodeInfo = { + const nodeInfo: NodeType = { sizingStyle, paddingSize, borderSize, @@ -85,7 +92,7 @@ function calculateNodeStyling(node, useCache = false) { } export default function calculateNodeHeight( - uiTextNode, + uiTextNode: HTMLTextAreaElement, useCache = false, minRows: number | null = null, maxRows: number | null = null, @@ -98,7 +105,7 @@ export default function calculateNodeHeight( // Fix wrap="off" issue // https://github.com/ant-design/ant-design/issues/6577 if (uiTextNode.getAttribute('wrap')) { - hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap')); + hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap') as string); } else { hiddenTextarea.removeAttribute('wrap'); } @@ -119,7 +126,7 @@ export default function calculateNodeHeight( let minHeight = Number.MIN_SAFE_INTEGER; let maxHeight = Number.MAX_SAFE_INTEGER; let height = hiddenTextarea.scrollHeight; - let overflowY; + let overflowY: any; if (boxSizing === 'border-box') { // border-box: add border, since height = content + padding + border