Skip to content

Commit

Permalink
refactor(types): sync components types
Browse files Browse the repository at this point in the history
  • Loading branch information
PengBoUESTC authored Sep 2, 2023
1 parent 09ac60c commit 51ee4d4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 17 deletions.
47 changes: 46 additions & 1 deletion packages/taro-components/types/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ declare namespace ButtonProps {
reset
}
/** open-type 的合法值 */
type OpenType = keyof openTypeKeys['weapp'] | keyof openTypeKeys['alipay'] | keyof openTypeKeys['qq']
type OpenType =
| keyof openTypeKeys['weapp']
| keyof openTypeKeys['alipay']
| keyof openTypeKeys['qq']
| keyof openTypeKeys['tt']
/** open-type 的合法值 */
interface openTypeKeys {
weapp: {
Expand All @@ -293,6 +297,11 @@ declare namespace ButtonProps {
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
*/
getPhoneNumber
/**
* 手机号实时验证,向用户申请,并在用户同意后,快速填写和实时验证手机号。(*小程序插件中不能使用*)
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getRealtimePhoneNumber.html
*/
getRealtimePhoneNumber
/** 获取用户信息,可以从回调中获取到用户信息 */
getUserInfo
/** 打开APP,可以通过 app-parameter 属性设定向APP传的参数
Expand All @@ -305,6 +314,10 @@ declare namespace ButtonProps {
feedback
/** 获取用户头像,可以从回调中获得具体信息 */
chooseAvatar
/**
* 用户同意隐私协议按钮。可通过 bindagreeprivacyauthorization 监听用户同意隐私协议事件
*/
agreePrivacyAuthorization
}
/** 支付宝小程序专属的 open-type 合法值
* @see https://opendocs.alipay.com/mini/component/button
Expand Down Expand Up @@ -350,6 +363,35 @@ declare namespace ButtonProps {
/** 在自定义开放数据域组件中,向指定好友发起分享据 */
shareMessageToFriend
}
/** TT 小程序专属的 open-type 合法值
* @see https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/component/list/button/#open-type-%E7%9A%84%E5%90%88%E6%B3%95%E5%80%BC
*/
tt: {
/** 触发用户转发, 可以配合 data-channel 属性来设置分享的 channel,具体请参考 ShareParam */
share
/** 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息,详情请参见获取手机号 */
getPhoneNumber
/** 跳转到抖音IM客服,详情请参见抖音IM客服能力 */
im
/** 跳转到抖音平台客服,详情请参见平台客服能力 */
platformIm
/** 跳转视频播放页,详情请参见跳转视频播放页 */
navigateToVideoView
/** 跳转抖音号个人页,详情请参见跳转抖音号个人页 */
openAwemeUserProfile
/** 跳转抖音直播间,详情请参见跳转抖音直播间 */
openWebcastRoom
/** 写入系统日历,详情请参见写入系统日历 */
addCalendarEvent
/** 添加到桌面,详情请参见添加到桌面 */
addShortcut
/** 加群,详情请参见加群 */
joinGroup
/** 私信,详情请参见私信 */
privateMessage
/** 主动授权私信,详情请参见主动授权私信 */
authorizePrivateMessage
}
}
/** lang 的合法值 */
interface Lang {
Expand Down Expand Up @@ -426,6 +468,9 @@ declare namespace ButtonProps {
*/
sign: string
}
interface onGetRealTimePhoneNumberEventDetail {
code: string
}
interface onOpenSettingEventDetail {
/* 打开授权设置页的调用状态 */
errMsg: string
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-components/types/ScrollView.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentType } from 'react'
import { StandardProps, CommonEventFunction, BaseEventOrigFunction } from './common'
import { BaseEventOrigFunction, CommonEventFunction, StandardProps } from './common'
interface ScrollViewProps extends StandardProps {
/** 允许横向滚动
* @default false
Expand Down Expand Up @@ -157,7 +157,7 @@ interface ScrollViewProps extends StandardProps {
* center - 目标节点显示在视口中间
* end - 目标节点显示在视口结束处
* nearest - 目标节点在就近的视口边缘显示,若节点已在视口内则不触发滚动
* @supported weapp
* @supported weapp, h5
* @default 'start'
*/
scrollIntoViewAlignment?: 'start' | 'center' | 'end' | 'nearest'
Expand Down
4 changes: 0 additions & 4 deletions packages/taro-components/types/ShareElement.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ interface ShareElementProps extends StandardProps {
* @deprecated 使用mapkey替换key
*/
key?: string
/** 映射标记
* @supported weapp
*/
mapkey?: string
/** 映射标记
* @supported alipay
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components/types/Textarea.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ interface TextareaProps extends StandardProps, FormItemProps {
/** 点击键盘右下角按钮时是否保持键盘不收起
* @supported weapp, swan, tt
*/
confirmHold?: string
confirmHold?: boolean
/** 组件名字,用于表单提交获取数据。
* @supported alipay
*/
Expand Down
27 changes: 18 additions & 9 deletions packages/taro-components/types/index.vue3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { AdCustomProps } from './AdCustom'
import { AudioProps } from './Audio'
import { ButtonProps } from './Button'
import { CameraProps } from './Camera'
import { CanvasProps } from './Canvas'
import { ChannelLiveProps } from './ChannelLive'
import { ChannelVideoProps } from './ChannelVideo'
import { CanvasProps } from './Canvas'
import { CheckboxProps } from './Checkbox'
import { CheckboxGroupProps } from './CheckboxGroup'
import { StandardProps } from './common'
Expand All @@ -30,17 +30,20 @@ import { CustomWrapperProps } from './CustomWrapper'
import { EditorProps } from './Editor'
import { FormProps } from './Form'
import { FunctionalPageNavigatorProps } from './FunctionalPageNavigator'
import { GridViewProps } from './GridView'
import { IconProps } from './Icon'
import { ImageProps } from './Image'
import { InputProps } from './Input'
import { KeyboardAccessoryProps } from './KeyboardAccessory'
import { LabelProps } from './Label'
import { ListViewProps } from './ListView'
import { LivePlayerProps } from './LivePlayer'
import { LivePusherProps } from './LivePusher'
import { MapProps } from './Map'
import { MatchMediaProps } from './MatchMedia'
import { MovableAreaProps } from './MovableArea'
import { MovableViewProps } from './MovableView'
import { NativeSlotProps } from './NativeSlot'
import { NavigationBarProps } from './NavigationBar'
import { NavigatorProps } from './Navigator'
import { OfficialAccountProps } from './OfficialAccount'
Expand All @@ -52,14 +55,18 @@ import {
PickerRegionProps, PickerSelectorProps, PickerTimeProps
} from './Picker'
import { PickerViewProps } from './PickerView'
import { PickerViewColumnProps } from './PickerViewColumn'
import { ProgressProps } from './Progress'
import { RadioProps } from './Radio'
import { RadioGroupProps } from './RadioGroup'
import { RichTextProps } from './RichText'
import { RootPortalProps } from './RootPortal'
import { ScrollViewProps } from './ScrollView'
import { ShareElementProps } from './ShareElement'
import { SliderProps } from './Slider'
import { SlotProps } from './Slot'
import { StickyHeaderProps } from './StickyHeader'
import { StickySectionProps } from './StickySection'
import { SwiperProps } from './Swiper'
import { SwiperItemProps } from './SwiperItem'
import { SwitchProps } from './Switch'
Expand All @@ -69,16 +76,18 @@ import { VideoProps } from './Video'
import { ViewProps } from './View'
import { VoipRoomProps } from './VoipRoom'
import { WebViewProps } from './WebView'
import { RootPortalProps } from './RootPortal'
import { PickerViewColumnProps } from './PickerViewColumn'
import { NativeSlotProps } from './NativeSlot'
import { GridViewProps } from './GridView'
import { ListViewProps } from './ListView'
import { StickyHeaderProps } from './StickyHeader'
import { StickySectionProps } from './StickySection'

/** 因为react的事件是CamelCase而vue得是Camelcase, 所以需要转换 */
type OnCamelCaseToOnCamelcase<T extends string> = T extends `on${infer Rest}`
? `on${Capitalize<Lowercase<Rest>>}`
: T;

type TransformCamelCase<T extends Record<string, any>> = {
[key in keyof T as OnCamelCaseToOnCamelcase<key>]: T[key]
}

/** 联合类型不能用omit(比如picker) */
type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never
type DistributiveOmit<T, K extends keyof T> = T extends unknown ? TransformCamelCase<Omit<T, K>> : never

interface SlimProps {
class?: any
Expand Down

0 comments on commit 51ee4d4

Please sign in to comment.