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', [`${this.props.prefixCls}-sm`]: size === 'small',
}, className); }, className);
return <RcInputNumber ref={c => this.inputNumberRef = c} className={inputNumberClass} {...others} />; return <RcInputNumber ref={(c: any) => this.inputNumberRef = c} className={inputNumberClass} {...others} />;
} }
focus() { focus() {

@ -6,7 +6,7 @@ import Group from './Group';
import Search from './Search'; import Search from './Search';
import TextArea from './TextArea'; import TextArea from './TextArea';
function fixControlledValue(value) { function fixControlledValue(value: undefined | null | string) {
if (typeof value === 'undefined' || value === null) { if (typeof value === 'undefined' || value === null) {
return ''; return '';
} }
@ -82,7 +82,7 @@ export default class Input extends React.Component<InputProps, any> {
input: HTMLInputElement; input: HTMLInputElement;
handleKeyDown = (e) => { handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const { onPressEnter, onKeyDown } = this.props; const { onPressEnter, onKeyDown } = this.props;
if (e.keyCode === 13 && onPressEnter) { if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e); onPressEnter(e);
@ -109,11 +109,11 @@ export default class Input extends React.Component<InputProps, any> {
}); });
} }
saveInput = (node) => { saveInput = (node: HTMLInputElement) => {
this.input = node; this.input = node;
} }
renderLabeledInput(children) { renderLabeledInput(children: React.ReactElement<any>) {
const props = this.props; const props = this.props;
// Not wrap when there is not addons // Not wrap when there is not addons
if ((!props.addonBefore && !props.addonAfter)) { 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; const { props } = this;
if (!('prefix' in props || 'suffix' in props)) { if (!('prefix' in props || 'suffix' in props)) {
return children; return children;

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

@ -4,14 +4,14 @@ import classNames from 'classnames';
import { AbstractInputProps } from './Input'; import { AbstractInputProps } from './Input';
import calculateNodeHeight from './calculateNodeHeight'; import calculateNodeHeight from './calculateNodeHeight';
function onNextFrame(cb) { function onNextFrame(cb: () => void) {
if (window.requestAnimationFrame) { if (window.requestAnimationFrame) {
return window.requestAnimationFrame(cb); return window.requestAnimationFrame(cb);
} }
return window.setTimeout(cb, 1); return window.setTimeout(cb, 1);
} }
function clearNextFrameAction(nextFrameId) { function clearNextFrameAction(nextFrameId: number) {
if (window.cancelAnimationFrame) { if (window.cancelAnimationFrame) {
window.cancelAnimationFrame(nextFrameId); window.cancelAnimationFrame(nextFrameId);
} else { } else {
@ -52,7 +52,7 @@ export default class TextArea extends React.Component<TextAreaProps & HTMLTextar
this.resizeTextarea(); this.resizeTextarea();
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps: TextAreaProps) {
// Re-render with the new content then recalculate the height as required. // Re-render with the new content then recalculate the height as required.
if (this.props.value !== nextProps.value) { if (this.props.value !== nextProps.value) {
if (this.nextFrameActionId) { 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)) { if (!('value' in this.props)) {
this.resizeTextarea(); 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; const { onPressEnter, onKeyDown } = this.props;
if (e.keyCode === 13 && onPressEnter) { if (e.keyCode === 13 && onPressEnter) {
onPressEnter(e); onPressEnter(e);
@ -108,7 +108,7 @@ export default class TextArea extends React.Component<TextAreaProps & HTMLTextar
} }
} }
saveTextAreaRef = (textArea) => { saveTextAreaRef = (textArea: HTMLTextAreaElement) => {
this.textAreaRef = textArea; this.textAreaRef = textArea;
} }

@ -34,15 +34,22 @@ const SIZING_STYLE = [
'box-sizing', 'box-sizing',
]; ];
let computedStyleCache = {}; export interface NodeType {
let hiddenTextarea; 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 = ( const nodeRef = (
node.getAttribute('id') || node.getAttribute('id') ||
node.getAttribute('data-reactid') || node.getAttribute('data-reactid') ||
node.getAttribute('name') node.getAttribute('name')
); ) as string;
if (useCache && computedStyleCache[nodeRef]) { if (useCache && computedStyleCache[nodeRef]) {
return computedStyleCache[nodeRef]; return computedStyleCache[nodeRef];
@ -70,7 +77,7 @@ function calculateNodeStyling(node, useCache = false) {
.map(name => `${name}:${style.getPropertyValue(name)}`) .map(name => `${name}:${style.getPropertyValue(name)}`)
.join(';'); .join(';');
const nodeInfo = { const nodeInfo: NodeType = {
sizingStyle, sizingStyle,
paddingSize, paddingSize,
borderSize, borderSize,
@ -85,7 +92,7 @@ function calculateNodeStyling(node, useCache = false) {
} }
export default function calculateNodeHeight( export default function calculateNodeHeight(
uiTextNode, uiTextNode: HTMLTextAreaElement,
useCache = false, useCache = false,
minRows: number | null = null, minRows: number | null = null,
maxRows: number | null = null, maxRows: number | null = null,
@ -98,7 +105,7 @@ export default function calculateNodeHeight(
// Fix wrap="off" issue // Fix wrap="off" issue
// https://github.com/ant-design/ant-design/issues/6577 // https://github.com/ant-design/ant-design/issues/6577
if (uiTextNode.getAttribute('wrap')) { if (uiTextNode.getAttribute('wrap')) {
hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap')); hiddenTextarea.setAttribute('wrap', uiTextNode.getAttribute('wrap') as string);
} else { } else {
hiddenTextarea.removeAttribute('wrap'); hiddenTextarea.removeAttribute('wrap');
} }
@ -119,7 +126,7 @@ export default function calculateNodeHeight(
let minHeight = Number.MIN_SAFE_INTEGER; let minHeight = Number.MIN_SAFE_INTEGER;
let maxHeight = Number.MAX_SAFE_INTEGER; let maxHeight = Number.MAX_SAFE_INTEGER;
let height = hiddenTextarea.scrollHeight; let height = hiddenTextarea.scrollHeight;
let overflowY; let overflowY: any;
if (boxSizing === 'border-box') { if (boxSizing === 'border-box') {
// border-box: add border, since height = content + padding + border // border-box: add border, since height = content + padding + border

Loading…
Cancel
Save