Skip to content

Commit 8665826

Browse files
ext.wuguorui1ext.wuguorui1
authored andcommitted
feat(component): 增加类型声明支持
1 parent 518f50b commit 8665826

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/taro-components/src/components/button/button.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Component, h, Prop, State, ComponentInterface, Event, EventEmitter, Listen, Element, Host } from '@stencil/core'
22
import classNames from 'classnames'
3+
import { withAscfAdapter } from 'src/common/ascf-adapter'
4+
35

46
@Component({
57
tag: 'taro-button-core',
@@ -104,3 +106,6 @@ export class Button implements ComponentInterface {
104106
)
105107
}
106108
}
109+
110+
111+

packages/taro-components/types/Button.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,33 @@ declare namespace ButtonProps {
440440
authorizePrivateMessage
441441
}
442442
}
443+
444+
declare namespace TaroGeneral {
445+
interface ENV_TYPE {
446+
ascf: boolean
447+
}
448+
}
449+
450+
type ASCFAdaptedProps<Props, Mapping> = {
451+
[K in keyof Props]:
452+
K extends keyof Mapping
453+
? Mapping[K]['ascfProp'] extends string
454+
? Props[K]
455+
: never
456+
: Props[K]
457+
} & {
458+
[K in keyof Mapping as Mapping[K]['ascfProp']]?: any
459+
};
460+
interface ButtonProps {
461+
size?: 'mini' | 'small' | 'default' | 'large'
462+
loading?: boolean
463+
}
464+
465+
type TaroButtonProps =
466+
TaroGeneral.ENV_TYPE['ascf'] extends true
467+
? ASCFAdaptedProps<ButtonProps, typeof coreMappings.Button>
468+
: ButtonProps;
469+
443470
/** lang 的合法值 */
444471
interface Lang {
445472
/** 英文 */

0 commit comments

Comments
 (0)