Skip to content

Commit b97add0

Browse files
committed
refactor(types): 完善类型声明
1 parent 6153cd7 commit b97add0

File tree

35 files changed

+102
-174
lines changed

35 files changed

+102
-174
lines changed

packages/taro-ui-demo-rn/src/pages/form/input/index.tsx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { AtForm, AtInput } from 'taro-ui'
33
import { View } from '@tarojs/components'
44
import { ImageBackground } from 'react-native'
55
import { BaseEventOrig } from '@tarojs/components/types/common'
6-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
7-
// @ts-ignore
86
import { InputProps } from '@tarojs/components/types/Input'
97
import Taro from '@tarojs/taro'
108
import DocsHeader from '../../components/doc-header'
@@ -32,7 +30,9 @@ interface IndexState {
3230
[key: string]: string | boolean | number
3331
}
3432

35-
export default class Index extends React.Component<{}, IndexState> {
33+
interface IndexProps {}
34+
35+
export default class Index extends React.Component<IndexProps, IndexState> {
3636
public constructor(props: any) {
3737
super(props)
3838
this.state = {
@@ -53,12 +53,12 @@ export default class Index extends React.Component<{}, IndexState> {
5353
value16: '',
5454
value17: '',
5555
disabled: false,
56-
second: 60,
56+
second: 60
5757
}
5858
}
5959

6060
public config: Taro.PageConfig = {
61-
navigationBarTitleText: 'Taro UI',
61+
navigationBarTitleText: 'Taro UI'
6262
}
6363

6464
private showTipText(): string {
@@ -68,18 +68,18 @@ export default class Index extends React.Component<{}, IndexState> {
6868
private sendCode(): void {
6969
if (this.state.disabled) return
7070
this.setState({
71-
disabled: true,
71+
disabled: true
7272
})
7373
// 倒计时
7474
const timer = setInterval(() => {
7575
if (this.state.second > 0) {
7676
this.setState({
77-
second: this.state.second - 1,
77+
second: this.state.second - 1
7878
})
7979
} else {
8080
this.setState({
8181
second: 60,
82-
disabled: false,
82+
disabled: false
8383
})
8484
clearInterval(timer)
8585
}
@@ -88,7 +88,7 @@ export default class Index extends React.Component<{}, IndexState> {
8888

8989
private handleInput(stateName: string, value: string): void {
9090
this.setState({
91-
[stateName]: value,
91+
[stateName]: value
9292
})
9393
}
9494

@@ -104,19 +104,17 @@ export default class Index extends React.Component<{}, IndexState> {
104104
Taro.showToast({
105105
title: '请输入数字',
106106
icon: 'success',
107-
duration: 2000,
107+
duration: 2000
108108
})
109109
}
110110

111111
private handleKeyboardHeightChange(
112-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
113-
// @ts-ignore
114-
event: BaseEventOrig<InputProps.onKeyboardHeightChangeEventDetail>,
112+
event: BaseEventOrig<InputProps.onKeyboardHeightChangeEventDetail>
115113
): void {
116114
Taro.showToast({
117115
title: `高度 ${event.detail.height}`,
118116
icon: 'success',
119-
duration: 2000,
117+
duration: 2000
120118
})
121119
}
122120

@@ -283,10 +281,8 @@ export default class Index extends React.Component<{}, IndexState> {
283281
placeholder='监听键盘高度事件'
284282
value={this.state.value17}
285283
onChange={this.handleInput.bind(this, 'value17')}
286-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
287-
// @ts-ignore
288284
onKeyboardHeightChange={this.handleKeyboardHeightChange.bind(
289-
this,
285+
this
290286
)}
291287
/>
292288
</AtForm>
@@ -317,10 +313,10 @@ export default class Index extends React.Component<{}, IndexState> {
317313
<ImageBackground
318314
style={{
319315
width: Taro.pxTransform(145),
320-
height: Taro.pxTransform(60),
316+
height: Taro.pxTransform(60)
321317
}}
322318
source={{
323-
uri: 'https://taro-ui.aotu.io/h5/static/images/verification_code.png',
319+
uri: 'https://taro-ui.aotu.io/h5/static/images/verification_code.png'
324320
}}
325321
resizeMode='cover'
326322
/>
@@ -338,7 +334,7 @@ export default class Index extends React.Component<{}, IndexState> {
338334
style={{
339335
color: this.state.disabled ? '#FF4949' : undefined,
340336
fontSize: 12,
341-
width: 90,
337+
width: 90
342338
}}
343339
onClick={this.sendCode.bind(this)}
344340
>

packages/taro-ui-demo-rn/src/pages/panel/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ interface PanelBasicState {
2626
currentId: string
2727
}
2828

29+
interface PanelBasicProps {}
30+
2931
const RN_NOT_SUPOORT = ['']
3032

31-
export default class PanelBasic extends React.Component<{}, PanelBasicState> {
33+
export default class PanelBasic extends React.Component<
34+
PanelBasicProps,
35+
PanelBasicState
36+
> {
3237
public config: Taro.PageConfig = {
3338
navigationBarTitleText: 'Taro UI'
3439
}
@@ -292,8 +297,6 @@ export default class PanelBasic extends React.Component<{}, PanelBasicState> {
292297
}
293298

294299
public componentDidMount(): void {
295-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
296-
// @ts-ignore
297300
const { id = '' } = Taro.Current.router.params
298301
this.setState({
299302
currentId: id.toLowerCase() || ''

packages/taro-ui-demo/src/pages/form/input/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from 'react'
22
import { AtForm, AtInput } from 'taro-ui'
33
import { Image, View } from '@tarojs/components'
44
import { BaseEventOrig } from '@tarojs/components/types/common'
5-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
6-
// @ts-ignore
75
import { InputProps } from '@tarojs/components/types/Input'
86
import Taro from '@tarojs/taro'
97
import verificationCode from '../../../assets/images/verification_code.png'
@@ -32,7 +30,9 @@ interface IndexState {
3230
[key: string]: string | boolean | number
3331
}
3432

35-
export default class Index extends React.Component<{}, IndexState> {
33+
interface IndexState {}
34+
35+
export default class Index extends React.Component<IndexState, IndexState> {
3636
public constructor(props: any) {
3737
super(props)
3838
this.state = {
@@ -109,8 +109,6 @@ export default class Index extends React.Component<{}, IndexState> {
109109
}
110110

111111
private handleKeyboardHeightChange(
112-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
113-
// @ts-ignore
114112
event: BaseEventOrig<InputProps.onKeyboardHeightChangeEventDetail>
115113
): void {
116114
Taro.showToast({
@@ -283,8 +281,6 @@ export default class Index extends React.Component<{}, IndexState> {
283281
placeholder='监听键盘高度事件'
284282
value={this.state.value17}
285283
onChange={this.handleInput.bind(this, 'value17')}
286-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
287-
// @ts-ignore
288284
onKeyboardHeightChange={this.handleKeyboardHeightChange.bind(
289285
this
290286
)}

packages/taro-ui-demo/src/pages/panel/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ interface PanelBasicState {
2525
}
2626
currentId: string
2727
}
28-
29-
export default class PanelBasic extends React.Component<{}, PanelBasicState> {
28+
interface PanelBasicProps {}
29+
export default class PanelBasic extends React.Component<
30+
PanelBasicProps,
31+
PanelBasicState
32+
> {
3033
public config: Taro.PageConfig = {
3134
navigationBarTitleText: 'Taro UI'
3235
}
@@ -290,8 +293,6 @@ export default class PanelBasic extends React.Component<{}, PanelBasicState> {
290293
}
291294

292295
public componentDidMount(): void {
293-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
294-
// @ts-ignore
295296
const { id } = Taro.Current.router.params
296297
this.setState({
297298
currentId: id.toLowerCase() || ''

packages/taro-ui/rn/components/float-layout/index.tsx

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ScrollView, Text, View } from '@tarojs/components'
55
import { Modal, Animated, Dimensions } from 'react-native'
66
import {
77
AtFloatLayoutProps,
8-
AtFloatLayoutState,
8+
AtFloatLayoutState
99
} from '../../../types/float-layout'
1010
import { handleTouchScroll } from '../../common/utils'
1111
import AtIcon from '../icon'
@@ -25,7 +25,7 @@ export default class AtFloatLayout extends React.Component<
2525
const { isOpened } = props
2626
this.state = {
2727
_isOpened: isOpened,
28-
translateY: 0,
28+
translateY: 0
2929
}
3030
}
3131

@@ -43,7 +43,7 @@ export default class AtFloatLayout extends React.Component<
4343

4444
animating = false
4545

46-
private animateLayout(isOpened: boolean, cb?: Function): void {
46+
private animateLayout(isOpened: boolean, cb?: () => void): void {
4747
this.animating = true
4848
let fromValue
4949
let toValue
@@ -61,36 +61,33 @@ export default class AtFloatLayout extends React.Component<
6161

6262
this.setState(
6363
{
64-
translateY,
64+
translateY
6565
},
6666
() => {
6767
setTimeout(() => {
6868
this.setState(
6969
{
70-
_isOpened: isOpened,
70+
_isOpened: isOpened
7171
},
7272
() => {
7373
cb && cb()
74-
},
74+
}
7575
)
7676
}, setStateDelay)
7777

7878
Animated.timing(this.state.translateY, {
7979
toValue,
8080
duration,
81-
useNativeDriver: true,
81+
useNativeDriver: true
8282
}).start(() => {
8383
this.animating = false
8484
})
85-
},
85+
}
8686
)
8787
}
8888

8989
private handleClose = (): void => {
9090
if (typeof this.props.onClose === 'function') {
91-
// TODO: Fix typings
92-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
93-
// @ts-ignore
9491
this.props.onClose()
9592
}
9693
}
@@ -112,15 +109,15 @@ export default class AtFloatLayout extends React.Component<
112109
scrollLeft,
113110
upperThreshold,
114111
lowerThreshold,
115-
scrollWithAnimation,
112+
scrollWithAnimation
116113
} = this.props
117114

118115
const rootClass = classNames(
119116
'at-float-layout',
120117
{
121-
'at-float-layout--active': _isOpened,
118+
'at-float-layout--active': _isOpened
122119
},
123-
this.props.className,
120+
this.props.className
124121
)
125122

126123
return (
@@ -162,14 +159,8 @@ export default class AtFloatLayout extends React.Component<
162159
upperThreshold={upperThreshold}
163160
lowerThreshold={lowerThreshold}
164161
scrollWithAnimation={scrollWithAnimation}
165-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
166-
// @ts-ignore // TODO: Fix typings
167162
onScroll={this.props.onScroll}
168-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
169-
// @ts-ignore // TODO: Fix typings
170163
onScrollToLower={this.props.onScrollToLower}
171-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
172-
// @ts-ignore // TODO: Fix typings
173164
onScrollToUpper={this.props.onScrollToUpper}
174165
className='layout-body__content'
175166
>
@@ -189,7 +180,7 @@ AtFloatLayout.defaultProps = {
189180

190181
scrollY: true,
191182
scrollX: false,
192-
scrollWithAnimation: false,
183+
scrollWithAnimation: false
193184
}
194185

195186
AtFloatLayout.propTypes = {
@@ -205,5 +196,5 @@ AtFloatLayout.propTypes = {
205196
onClose: PropTypes.func,
206197
onScroll: PropTypes.func,
207198
onScrollToLower: PropTypes.func,
208-
onScrollToUpper: PropTypes.func,
199+
onScrollToUpper: PropTypes.func
209200
}

packages/taro-ui/rn/components/input/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ export default class AtInput extends React.Component<AtInputProps> {
194194
onFocus={this.handleFocus}
195195
onBlur={this.handleBlur}
196196
onConfirm={this.handleConfirm}
197-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
198-
// @ts-ignore
199197
onKeyboardHeightChange={this.handleKeyboardHeightChange}
200198
/>
201199
{clear && value && (

packages/taro-ui/rn/components/modal/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default class AtModal extends React.Component<
7272
}
7373
}
7474

75-
private animateLayout(isOpened: boolean, cb?: Function): void {
75+
private animateLayout(isOpened: boolean, cb?: () => void): void {
7676
let fromValue
7777
let toValue
7878
let setStateDelay = 0
@@ -152,8 +152,6 @@ export default class AtModal extends React.Component<
152152
<View className='content-simple'>
153153
{isWEB ? (
154154
<Text
155-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
156-
// @ts-ignore
157155
dangerouslySetInnerHTML={{
158156
__html: content.replace(/\n/g, '<br/>')
159157
}}

packages/taro-ui/src/common/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const objectToString = (style: object | string): string => {
1414
return ''
1515
}
1616

17-
export default class AtComponent<P = {}, S = {}> extends Component<P, S> {
17+
export default class AtComponent<P, S> extends Component<P, S> {
1818
/**
1919
* 合并 style
2020
* @param {Object|String} style1

packages/taro-ui/src/components/action-sheet/body/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import React from 'react'
33
import { View } from '@tarojs/components'
44
import { AtActionSheetBodyProps } from '../../../../types/action-sheet'
55

6-
export default class AtActionSheetBody extends React.Component<
7-
AtActionSheetBodyProps
8-
> {
6+
export default class AtActionSheetBody extends React.Component<AtActionSheetBodyProps> {
97
public render(): JSX.Element {
108
const rootClass = classNames('at-action-sheet__body', this.props.className)
119
return <View className={rootClass}>{this.props.children}</View>

packages/taro-ui/src/components/action-sheet/body/item/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import React from 'react'
44
import { View } from '@tarojs/components'
55
import { AtActionSheetItemProps } from '../../../../../types/action-sheet'
66

7-
export default class AtActionSheetItem extends React.Component<
8-
AtActionSheetItemProps
9-
> {
7+
export default class AtActionSheetItem extends React.Component<AtActionSheetItemProps> {
108
public static defaultProps: AtActionSheetItemProps
119
public static propTypes: InferProps<AtActionSheetItemProps>
1210

0 commit comments

Comments
 (0)