Fix implicit any error for Input

pull/8292/head
Wei Zhu 7 years ago
parent bcbdd12ce1
commit 05c702838d

@ -38,7 +38,7 @@ export default class InputNumber extends React.Component<InputNumberProps, any>
[`${this.props.prefixCls}-sm`]: size === 'small',
}, className);
return <RcInputNumber ref={c => this.inputNumberRef = c} className={inputNumberClass} {...others} />;
return <RcInputNumber ref={(c: any) => this.inputNumberRef = c} className={inputNumberClass} {...others} />;
}
focus() {

@ -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<InputProps, any> {
input: HTMLInputElement;
handleKeyDown = (e) => {
handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const { onPressEnter, onKeyDown } = this.props;
if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e);
@ -109,11 +109,11 @@ export default class Input extends React.Component<InputProps, any> {
});
}
saveInput = (node) => {
saveInput = (node: HTMLInputElement) => {
this.input = node;
}
renderLabeledInput(children) {
renderLabeledInput(children: React.ReactElement<any>) {
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<InputProps, any> {
);
}
renderLabeledIcon(children) {
renderLabeledIcon(children: React.ReactElement<any>) {
const { props } = this;
if (!('prefix' in props || 'suffix' in props)) {
return children;

@ -27,7 +27,7 @@ export default class Search extends React.Component<SearchProps, any> {
this.input.focus();
}
saveInput = (node) => {
saveInput = (node: Input) => {
this.input = node;
}

@ -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<TextAreaProps & HTMLTextar
this.resizeTextarea();
}
componentWillReceiveProps(nextProps) {
componentWillReceiveProps(nextProps: TextAreaProps) {
// Re-render with the new content then recalculate the height as required.
if (this.props.value !== nextProps.value) {
if (this.nextFrameActionId) {
@ -88,7 +88,7 @@ export default class TextArea extends React.Component<TextAreaProps & HTMLTextar
});
}
handleTextareaChange = (e) => {
handleTextareaChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
if (!('value' in this.props)) {
this.resizeTextarea();
}
@ -98,7 +98,7 @@ export default class TextArea extends React.Component<TextAreaProps & HTMLTextar
}
}
handleKeyDown = (e) => {
handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
const { onPressEnter, onKeyDown } = this.props;
if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e);
@ -108,7 +108,7 @@ export default class TextArea extends React.Component<TextAreaProps & HTMLTextar
}
}
saveTextAreaRef = (textArea) => {
saveTextAreaRef = (textArea: HTMLTextAreaElement) => {
this.textAreaRef = textArea;
}

@ -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

Loading…
Cancel
Save