Skip to content

Commit 05a4589

Browse files
committed
fix: strictNullCheck with defaultProps
DefinitelyTyped/DefinitelyTyped#11640
1 parent 7be8e11 commit 05a4589

File tree

10 files changed

+32
-17
lines changed

10 files changed

+32
-17
lines changed

components/badge/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class Badge extends React.Component<BadgeProps, any> {
1818
children, text, size, overflowCount, dot, corner, ...restProps, // todo: hot
1919
} = this.props;
2020

21-
text = typeof text === 'number' && text > overflowCount ? `${overflowCount}+` : text;
21+
text = typeof text === 'number' && text > (overflowCount as number) ? `${overflowCount}+` : text;
2222

2323
// dot mode don't need text
2424
if (dot) {

components/badge/index.web.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class Badge extends React.Component<BadgeProps, any> {
1616
className, prefixCls,
1717
children, text, size, overflowCount, dot, corner, hot, ...restProps,
1818
} = this.props;
19-
19+
overflowCount = overflowCount as number;
2020
text = typeof text === 'number' && text > overflowCount ? `${overflowCount}+` : text;
2121

2222
// dot mode don't need text

components/grid/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export default class Grid extends React.Component<GridProps, any> {
2424
}
2525

2626
render() {
27-
const { data, hasLine, columnNum, isCarousel, carouselMaxRow, onClick = () => {}, styles } = this.props;
28-
27+
const { data, hasLine, isCarousel, onClick = () => {}, styles } = this.props;
28+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11640
29+
const columnNum = this.props.columnNum as number;
30+
const carouselMaxRow = this.props.carouselMaxRow as number;
2931
const dataLength = data && data.length || 0;
3032
const rowCount = Math.ceil(dataLength / columnNum);
3133

components/grid/index.web.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export default class Grid extends React.Component<GridProps, any> {
2020
render() {
2121
const {
2222
prefixCls, className,
23-
data, hasLine, columnNum, isCarousel, carouselMaxRow, onClick = () => {},
23+
data, hasLine, isCarousel, onClick = () => {},
2424
} = this.props;
2525

26+
const columnNum = this.props.columnNum as number;
27+
const carouselMaxRow = this.props.carouselMaxRow as number;
28+
2629
const dataLength = data && data.length || 0;
2730
const rowCount = Math.ceil(dataLength / columnNum);
2831

components/input-item/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export default class InputItem extends React.Component<InputItemProps, any> {
5050
}
5151

5252
onChange = (text) => {
53-
const { maxLength, onChange, type } = this.props;
53+
const { onChange, type } = this.props;
54+
const maxLength = this.props.maxLength as number;
5455
switch (type) {
5556
case 'bankCard':
5657
text = text.replace(/\D/g, '');
@@ -95,10 +96,10 @@ export default class InputItem extends React.Component<InputItemProps, any> {
9596

9697
render() {
9798
const {
98-
value, defaultValue, type, style, clear, children, error, extra, labelNumber,
99+
value, defaultValue, type, style, clear, children, error, extra,
99100
last, onExtraClick = noop, onErrorClick = noop, styles,
100101
} = this.props;
101-
102+
const labelNumber = this.props.labelNumber as number;
102103
let valueProps;
103104
if ('value' in this.props) {
104105
valueProps = {

components/steps/StepsItem.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ export default class StepsItem extends React.Component<StepsItemProps, any> {
2121

2222
render() {
2323
const {
24-
size, current, index, last, title, description,
25-
status, errorTail, icon, styles,
24+
size, last, title, description,
25+
status, icon, styles,
2626
} = this.props;
2727

28+
const index = this.props.index as number;
29+
const current = this.props.current as number;
30+
const errorTail = this.props.errorTail as number;
31+
2832
let headCls: string = '';
2933
let tailTopCls: string = '';
3034
let tailBottomCls: string = '';

components/steps/index.web.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default class Steps extends React.Component<StepsProps, any> {
4141
}
4242
render() {
4343
this.stepRefs = [];
44-
const { children, current, status } = this.props;
44+
const { children, status } = this.props;
45+
const current = this.props.current as number;
4546
// flattern the array at first https://github.com/ant-design/ant-design-mobile/issues/934
4647
let newChildren: Array<any> = React.Children.map(children, item => item);
4748
newChildren = React.Children.map(newChildren, (item: any, index) => {

components/textarea-item/index.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export default class TextAreaItem extends React.Component<TextAreaItemProps, any
4545
onChange = (event) => {
4646
const text = event.nativeEvent.text;
4747
let height;
48-
const { autoHeight, rows, onChange } = this.props;
49-
48+
const { autoHeight, onChange } = this.props;
49+
const rows = this.props.rows as number;
5050
if (autoHeight) {
5151
height = event.nativeEvent.contentSize.height;
5252
} else if (rows > 1) {
@@ -67,9 +67,11 @@ export default class TextAreaItem extends React.Component<TextAreaItemProps, any
6767
render() {
6868
const { inputCount } = this.state;
6969
const {
70-
value, defaultValue, rows, error, clear, count, autoHeight, last, onErrorClick,
70+
value, defaultValue, error, clear, autoHeight, last, onErrorClick,
7171
styles, style,
7272
} = this.props;
73+
const rows = this.props.rows as number;
74+
const count = this.props.count as number;
7375

7476
let valueProps;
7577
if ('value' in this.props) {

components/textarea-item/index.web.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ export default class TextareaItem extends React.Component<TextareaItemProps, Tex
160160

161161
render() {
162162
let {
163-
prefixCls, prefixListCls, style, title, value, defaultValue, clear, rows, count,
163+
prefixCls, prefixListCls, style, title, value, defaultValue, clear,
164164
editable, disabled, error, className, labelNumber, autoHeight,
165165
} = this.props;
166-
166+
const count = this.props.count as number;
167+
const rows = this.props.rows as number;
167168
// note: remove `placeholderTextColor` prop for rn TextInput supports placeholderTextColor
168169
const otherProps = omit(this.props, ['prefixCls', 'prefixListCls', 'editable', 'style',
169170
'clear', 'children', 'error', 'className', 'count', 'labelNumber', 'title', 'onErrorClick',

components/toast/ToastContainer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default class ToastContainer extends React.Component<ToastProps, any> {
3737
}
3838

3939
componentDidMount() {
40-
const { onClose, duration, onAnimationEnd } = this.props;
40+
const { onClose, onAnimationEnd } = this.props;
41+
const duration = this.props.duration as number;
4142
const timing = Animated.timing;
4243
if (this.anim) {
4344
this.anim = null;

0 commit comments

Comments
 (0)