Skip to content

Commit 7651862

Browse files
authored
fix: app.use type error (#3079)
1 parent ddd50fe commit 7651862

File tree

61 files changed

+279
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+279
-364
lines changed

components/_util/type.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropType, VNodeChild } from 'vue';
1+
import { App, PropType, VNodeChild, Plugin } from 'vue';
22

33
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
44
// https://stackoverflow.com/questions/46176165/ways-to-get-string-literal-type-of-array-values-without-enum-overhead
@@ -31,3 +31,12 @@ export interface PropOptions<T = any, D = T> {
3131
}
3232

3333
export type VueNode = VNodeChild | JSX.Element;
34+
35+
export const withInstall = <T>(comp: T) => {
36+
const c = comp as any;
37+
c.install = function(app: App) {
38+
app.component(c.displayName || c.name, comp);
39+
};
40+
41+
return comp as T & Plugin;
42+
};

components/affix/index.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, CSSProperties, defineComponent, inject } from 'vue';
1+
import { CSSProperties, defineComponent, inject } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import classNames from '../_util/classNames';
44
import omit from 'omit.js';
@@ -7,6 +7,7 @@ import BaseMixin from '../_util/BaseMixin';
77
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame';
88
import { defaultConfigProvider } from '../config-provider';
99
import warning from '../_util/warning';
10+
import { withInstall } from '../_util/type';
1011
import {
1112
addObserveTarget,
1213
removeObserveTarget,
@@ -265,10 +266,5 @@ const Affix = defineComponent({
265266
);
266267
},
267268
});
268-
/* istanbul ignore next */
269-
Affix.install = function(app: App) {
270-
app.component(Affix.name, Affix);
271-
return app;
272-
};
273269

274-
export default Affix;
270+
export default withInstall(Affix);

components/alert/index.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, cloneVNode, defineComponent, App } from 'vue';
1+
import { inject, cloneVNode, defineComponent } from 'vue';
22
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
33
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined';
44
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined';
@@ -14,7 +14,7 @@ import PropTypes from '../_util/vue-types';
1414
import { getTransitionProps, Transition } from '../_util/transition';
1515
import { getComponent, isValidElement, findDOMNode } from '../_util/props-util';
1616
import { defaultConfigProvider } from '../config-provider';
17-
import { tuple } from '../_util/type';
17+
import { tuple, withInstall } from '../_util/type';
1818

1919
function noop() {}
2020

@@ -161,10 +161,4 @@ const Alert = defineComponent({
161161
},
162162
});
163163

164-
/* istanbul ignore next */
165-
Alert.install = function(app: App) {
166-
app.component(Alert.name, Alert);
167-
return app;
168-
};
169-
170-
export default Alert;
164+
export default withInstall(Alert);

components/anchor/index.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Anchor from './Anchor';
33
import AnchorLink from './AnchorLink';
44

@@ -10,6 +10,8 @@ Anchor.install = function(app: App) {
1010
app.component(Anchor.Link.name, Anchor.Link);
1111
return app;
1212
};
13-
export default Anchor as typeof Anchor & {
14-
readonly Link: typeof AnchorLink;
15-
};
13+
14+
export default Anchor as typeof Anchor &
15+
Plugin & {
16+
readonly Link: typeof AnchorLink;
17+
};

components/auto-complete/index.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, defineComponent, inject, provide } from 'vue';
1+
import { App, defineComponent, inject, provide, Plugin } from 'vue';
22
import Select, { SelectProps } from '../select';
33
import Input from '../input';
44
import InputElement from './InputElement';
@@ -147,7 +147,8 @@ AutoComplete.install = function(app: App) {
147147
return app;
148148
};
149149

150-
export default AutoComplete as typeof AutoComplete & {
151-
readonly Option: typeof Option;
152-
readonly OptGroup: typeof OptGroup;
153-
};
150+
export default AutoComplete as typeof AutoComplete &
151+
Plugin & {
152+
readonly Option: typeof Option;
153+
readonly OptGroup: typeof OptGroup;
154+
};

components/avatar/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import { App } from 'vue';
21
import Avatar from './Avatar';
2+
import { withInstall } from '../_util/type';
33

4-
/* istanbul ignore next */
5-
Avatar.install = function(app: App) {
6-
app.component(Avatar.name, Avatar);
7-
return app;
8-
};
9-
10-
export default Avatar;
4+
export default withInstall(Avatar);

components/back-top/index.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, defineComponent, inject, nextTick } from 'vue';
1+
import { defineComponent, inject, nextTick } from 'vue';
22
import classNames from '../_util/classNames';
33
import PropTypes from '../_util/vue-types';
44
import backTopTypes from './backTopTypes';
@@ -8,6 +8,7 @@ import BaseMixin from '../_util/BaseMixin';
88
import { getTransitionProps, Transition } from '../_util/transition';
99
import { defaultConfigProvider } from '../config-provider';
1010
import scrollTo from '../_util/scrollTo';
11+
import { withInstall } from '../_util/type';
1112

1213
function getDefaultTarget() {
1314
return window;
@@ -100,10 +101,4 @@ const BackTop = defineComponent({
100101
},
101102
});
102103

103-
/* istanbul ignore next */
104-
BackTop.install = function(app: App) {
105-
app.component(BackTop.name, BackTop);
106-
return app;
107-
};
108-
109-
export default BackTop;
104+
export default withInstall(BackTop);

components/badge/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import { App } from 'vue';
21
import Badge from './Badge';
2+
import { withInstall } from '../_util/type';
33

4-
/* istanbul ignore next */
5-
Badge.install = function(app: App) {
6-
app.component(Badge.name, Badge);
7-
return app;
8-
};
9-
10-
export default Badge;
4+
export default withInstall(Badge);

components/breadcrumb/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Breadcrumb from './Breadcrumb';
33
import BreadcrumbItem from './BreadcrumbItem';
44
import BreadcrumbSeparator from './BreadcrumbSeparator';
@@ -14,7 +14,8 @@ Breadcrumb.install = function(app: App) {
1414
return app;
1515
};
1616

17-
export default Breadcrumb as typeof Breadcrumb & {
18-
readonly Item: typeof BreadcrumbItem;
19-
readonly Separator: typeof BreadcrumbSeparator;
20-
};
17+
export default Breadcrumb as typeof Breadcrumb &
18+
Plugin & {
19+
readonly Item: typeof BreadcrumbItem;
20+
readonly Separator: typeof BreadcrumbSeparator;
21+
};

components/button/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Button from './button';
33
import ButtonGroup from './button-group';
44

@@ -11,6 +11,7 @@ Button.install = function(app: App) {
1111
return app;
1212
};
1313

14-
export default Button as typeof Button & {
15-
readonly Group: typeof ButtonGroup;
16-
};
14+
export default Button as typeof Button &
15+
Plugin & {
16+
readonly Group: typeof ButtonGroup;
17+
};

components/calendar/index.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, defineComponent, inject, PropType } from 'vue';
1+
import { defineComponent, inject, PropType } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import BaseMixin from '../_util/BaseMixin';
44
import { getOptionProps, hasProp } from '../_util/props-util';
@@ -10,7 +10,7 @@ import interopDefault from '../_util/interopDefault';
1010
import { defaultConfigProvider } from '../config-provider';
1111
import enUS from './locale/en_US';
1212
import { checkValidate, stringToMoment, momentToString, TimeType } from '../_util/moment-util';
13-
import { tuple } from '../_util/type';
13+
import { tuple, withInstall } from '../_util/type';
1414

1515
function noop() {
1616
return null;
@@ -252,10 +252,6 @@ const Calendar = defineComponent({
252252
},
253253
});
254254

255-
/* istanbul ignore next */
256-
Calendar.install = function(app: App) {
257-
app.component(Calendar.name, Calendar);
258-
return app;
259-
};
260255
export { HeaderProps } from './Header';
261-
export default Calendar;
256+
257+
export default withInstall(Calendar);

components/card/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Card from './Card';
33
import Meta from './Meta';
44
import Grid from './Grid';
@@ -14,7 +14,8 @@ Card.install = function(app: App) {
1414
return app;
1515
};
1616

17-
export default Card as typeof Card & {
18-
readonly Meta: typeof Meta;
19-
readonly Grid: typeof Grid;
20-
};
17+
export default Card as typeof Card &
18+
Plugin & {
19+
readonly Meta: typeof Meta;
20+
readonly Grid: typeof Grid;
21+
};

components/carousel/index.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { App, defineComponent, inject } from 'vue';
1+
import { defineComponent, inject } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import debounce from 'lodash-es/debounce';
44
import hasProp, { getComponent } from '../_util/props-util';
55
import { defaultConfigProvider } from '../config-provider';
66
import warning from '../_util/warning';
77
import classNames from '../_util/classNames';
88
import SlickCarousel from '../vc-slick/src';
9-
import { tuple } from '../_util/type';
9+
import { tuple, withInstall } from '../_util/type';
1010

1111
// Carousel
1212
export const CarouselProps = {
@@ -164,10 +164,4 @@ const Carousel = defineComponent({
164164
},
165165
});
166166

167-
/* istanbul ignore next */
168-
Carousel.install = function(app: App) {
169-
app.component(Carousel.name, Carousel);
170-
return app;
171-
};
172-
173-
export default Carousel;
167+
export default withInstall(Carousel);

components/cascader/index.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, inject, provide, PropType, defineComponent, CSSProperties } from 'vue';
1+
import { inject, provide, PropType, defineComponent, CSSProperties } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import VcCascader from '../vc-cascader';
44
import arrayTreeFilter from 'array-tree-filter';
@@ -23,7 +23,7 @@ import BaseMixin from '../_util/BaseMixin';
2323
import { cloneElement } from '../_util/vnode';
2424
import warning from '../_util/warning';
2525
import { defaultConfigProvider } from '../config-provider';
26-
import { tuple, VueNode } from '../_util/type';
26+
import { tuple, VueNode, withInstall } from '../_util/type';
2727
import { RenderEmptyHandler } from '../config-provider/renderEmpty';
2828

2929
export interface CascaderOptionType {
@@ -611,9 +611,4 @@ const Cascader = defineComponent({
611611
},
612612
});
613613

614-
Cascader.install = function(app: App) {
615-
app.component(Cascader.name, Cascader);
616-
return app;
617-
};
618-
619-
export default Cascader;
614+
export default withInstall(Cascader);

components/checkbox/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Checkbox from './Checkbox';
33
import CheckboxGroup from './Group';
44

@@ -11,6 +11,7 @@ Checkbox.install = function(app: App) {
1111
return app;
1212
};
1313

14-
export default Checkbox as typeof Checkbox & {
15-
readonly Group: typeof CheckboxGroup;
16-
};
14+
export default Checkbox as typeof Checkbox &
15+
Plugin & {
16+
readonly Group: typeof CheckboxGroup;
17+
};

components/col/index.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { App } from 'vue';
21
import { Col } from '../grid';
3-
/* istanbul ignore next */
4-
Col.install = function(app: App) {
5-
app.component(Col.name, Col);
6-
return app;
7-
};
2+
import { withInstall } from '../_util/type';
83

9-
export default Col;
4+
export default withInstall(Col);

components/collapse/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'vue';
1+
import { App, Plugin } from 'vue';
22
import Collapse from './Collapse';
33
import CollapsePanel from './CollapsePanel';
44

@@ -11,6 +11,7 @@ Collapse.install = function(app: App) {
1111
return app;
1212
};
1313

14-
export default Collapse as typeof Collapse & {
15-
readonly Panel: typeof CollapsePanel;
16-
};
14+
export default Collapse as typeof Collapse &
15+
Plugin & {
16+
readonly Panel: typeof CollapsePanel;
17+
};

components/comment/index.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { App, defineComponent, inject } from 'vue';
1+
import { defineComponent, inject } from 'vue';
22
import PropsTypes from '../_util/vue-types';
33
import { getComponent, getSlot } from '../_util/props-util';
44
import { defaultConfigProvider } from '../config-provider';
5-
import { VueNode } from '../_util/type';
5+
import { VueNode, withInstall } from '../_util/type';
66
export const CommentProps = {
77
actions: PropsTypes.array,
88
/** The element to display as the comment author. */
@@ -93,9 +93,4 @@ const Comment = defineComponent({
9393
},
9494
});
9595

96-
/* istanbul ignore next */
97-
Comment.install = function(app: App) {
98-
app.component(Comment.name, Comment);
99-
return app;
100-
};
101-
export default Comment;
96+
export default withInstall(Comment);

components/config-provider/index.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { reactive, provide, VNodeTypes, PropType, defineComponent, App, watch } from 'vue';
1+
import { reactive, provide, VNodeTypes, PropType, defineComponent, watch } from 'vue';
22
import PropTypes from '../_util/vue-types';
33
import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty';
44
import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider';
55

66
import LocaleReceiver from '../locale-provider/LocaleReceiver';
7+
import { withInstall } from '../_util/type';
78

89
export type SizeType = 'small' | 'middle' | 'large' | undefined;
910

@@ -168,10 +169,4 @@ export const defaultConfigProvider: ConfigConsumerProps = {
168169
renderEmpty: defaultRenderEmpty,
169170
};
170171

171-
/* istanbul ignore next */
172-
ConfigProvider.install = function(app: App) {
173-
app.component(ConfigProvider.name, ConfigProvider);
174-
return app;
175-
};
176-
177-
export default ConfigProvider;
172+
export default withInstall(ConfigProvider);

0 commit comments

Comments
 (0)