Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix radio/checkbox/input/tabs/popup/.. ts type of build files #2475

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const classPrefixMixins = getClassPrefixMixins('checkbox');

export type CheckboxGroupInstance = InstanceType<typeof Group>;

interface CheckboxInstance extends Vue {
export interface CheckboxParentInjectInstance extends Vue {
checkboxGroup: CheckboxGroupInstance;
}

export default mixins(classPrefixMixins, Vue as VueConstructor<CheckboxInstance>).extend({
export default mixins(classPrefixMixins, Vue as VueConstructor<CheckboxParentInjectInstance>).extend({
name: 'TCheckbox',

inheritAttrs: false,
Expand Down
7 changes: 5 additions & 2 deletions src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ function getValidAttrs(obj: object): object {
return newObj;
}

interface InputInstance extends Vue {
export interface InputParentInjectInstance extends Vue {
composing: boolean;
tFormItem: InstanceType<typeof FormItem>;
}

export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input'), getGlobalIconMixins()).extend({
export default mixins(
getConfigReceiverMixins<InputParentInjectInstance, InputConfig>('input'),
getGlobalIconMixins(),
).extend({
name: 'TInput',
inheritAttrs: false,

Expand Down
6 changes: 3 additions & 3 deletions src/radio/radio.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Vue, { VueConstructor, VNode } from 'vue';
import { omit } from '../utils/helper';
import { renderContent } from '../utils/render-tnode';
import props from './props';
import { RadioGroupInstance, RadioButtonInstance } from './instance';
import props from './props';
import { emitEvent } from '../utils/event';
import { TdRadioProps } from './type';
import { getClassPrefixMixins } from '../config-provider/config-receiver';
import mixins from '../utils/mixins';

const classPrefixMixins = getClassPrefixMixins('radio');

interface RadioInstance extends Vue {
export interface RadioParentInjectInstance extends Vue {
radioGroup: RadioGroupInstance;
radioButton: RadioButtonInstance;
}

export default mixins(Vue as VueConstructor<RadioInstance>, classPrefixMixins).extend({
export default mixins(Vue as VueConstructor<RadioParentInjectInstance>, classPrefixMixins).extend({
name: 'TRadio',

inheritAttrs: false,
Expand Down
6 changes: 3 additions & 3 deletions src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import mixins from '../utils/mixins';

const classPrefixMixins = getClassPrefixMixins('tabs');

interface TabVue extends Vue {
export interface TabParentInjectVue extends Vue {
listPanels?: Array<VNode>;
}

export default mixins(Vue as VueConstructor<TabVue>, classPrefixMixins).extend({
export default mixins(Vue as VueConstructor<TabParentInjectVue>, classPrefixMixins).extend({
name: 'TTabs',
model: {
prop: 'value',
Expand All @@ -30,7 +30,7 @@ export default mixins(Vue as VueConstructor<TabVue>, classPrefixMixins).extend({

props: { ...props },

provide(): { parent: TabVue } {
provide(): { parent: TabParentInjectVue } {
return {
parent: this,
};
Expand Down
24 changes: 10 additions & 14 deletions src/utils/map-props.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Vue, { ComponentOptions, CreateElement, VueConstructor } from 'vue';
import Vue, { CreateElement, PluginObject } from 'vue';
import { ExtendedVue } from 'vue/types/vue';

const defaultModel = {
prop: 'value',
event: 'input',
};

function toCamel(str: string): string {
return str.replace(/-([a-z])/ig, (m, letter) => letter.toUpperCase());
return str.replace(/-([a-z])/gi, (m, letter) => letter.toUpperCase());
}

type PropOption = {
Expand All @@ -33,10 +34,7 @@ function getPropOptionMap(props: (string | PropOption)[], options: Option = {}):
const { model } = options;

function parseProp(propOption: PropOption): ParsedPropOption {
const {
name: propName,
...others
} = propOption;
const { name: propName, ...others } = propOption;
const camelName = propName.replace(/^[a-z]/, (letter: string) => letter.toUpperCase());
const defaultName = `default${camelName}`;
const dataName = `data${camelName}`;
Expand Down Expand Up @@ -76,8 +74,8 @@ function getPropOptionMap(props: (string | PropOption)[], options: Option = {}):
}

export default function (props: (string | PropOption)[], options: Option = {}) {
function mapProps(componentConstructor: VueConstructor | any) {
const component: ComponentOptions<Vue> = componentConstructor.prototype
function mapProps<T extends ExtendedVue<Vue, any, any, any, any>>(componentConstructor: T) {
const component = componentConstructor.prototype
? componentConstructor.prototype.constructor.options
: componentConstructor;
const model = options.model || defaultModel;
Expand Down Expand Up @@ -193,10 +191,7 @@ export default function (props: (string | PropOption)[], options: Option = {}) {

Object.keys(propOptionMap).forEach((propName: string): void => {
const { dataName, events } = propOptionMap[propName];
if (
propName in this.$vnode.componentOptions.propsData
|| typeof this[dataName] !== 'undefined'
) {
if (propName in this.$vnode.componentOptions.propsData || typeof this[dataName] !== 'undefined') {
propMap[propName] = this[dataName];
}
// 只监听第一个定义的事件,参数取第一个事件参数
Expand All @@ -222,7 +217,8 @@ export default function (props: (string | PropOption)[], options: Option = {}) {
},

on: {
...this._listeners as Record<string, any>,
// @ts-ignore
...(this._listeners as Record<string, any>),
...handlerMap,
},

Expand All @@ -245,7 +241,7 @@ export default function (props: (string | PropOption)[], options: Option = {}) {
},
...defineMethods,
},
});
}) as T & PluginObject<T>;
}

return mapProps;
Expand Down
Loading