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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 3 additions & 9 deletions
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 2 additions & 8 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 2 additions & 8 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 5 additions & 4 deletions
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+
};

0 commit comments

Comments
 (0)