types: using unknown instead of any (#8152)

* types: using unknown instead of any

* chore: UnknownProp
This commit is contained in:
neverland 2021-02-14 12:37:02 +08:00 committed by GitHub
parent 393b2a256f
commit 08e928111b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 81 additions and 56 deletions

View File

@ -1,4 +1,4 @@
import { createNamespace } from '../utils'; import { createNamespace, UnknownProp } from '../utils';
import { ACTION_BAR_KEY } from '../action-bar'; import { ACTION_BAR_KEY } from '../action-bar';
// Composition // Composition
@ -19,7 +19,7 @@ export default createComponent({
icon: String, icon: String,
color: String, color: String,
badge: [Number, String], badge: [Number, String],
iconClass: null, iconClass: UnknownProp,
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -17,7 +17,7 @@ export type ActionSheetAction = {
loading?: boolean; loading?: boolean;
disabled?: boolean; disabled?: boolean;
callback?: (action: ActionSheetAction) => void; callback?: (action: ActionSheetAction) => void;
className?: any; className?: unknown;
}; };
export default createComponent({ export default createComponent({

View File

@ -1,7 +1,7 @@
import { PropType } from 'vue'; import { PropType, CSSProperties } from 'vue';
// Utils // Utils
import { createNamespace, isDef } from '../utils'; import { createNamespace, isDef, UnknownProp } from '../utils';
// Composition // Composition
import { useRoute, routeProps } from '../composables/use-route'; import { useRoute, routeProps } from '../composables/use-route';
@ -23,10 +23,10 @@ export const cellProps = {
isLink: Boolean, isLink: Boolean,
required: Boolean, required: Boolean,
iconPrefix: String, iconPrefix: String,
titleStyle: null as any, valueClass: UnknownProp,
titleClass: null as any, labelClass: UnknownProp,
valueClass: null as any, titleClass: UnknownProp,
labelClass: null as any, titleStyle: (null as unknown) as PropType<string | CSSProperties>,
arrowDirection: String as PropType<CellArrowDirection>, arrowDirection: String as PropType<CellArrowDirection>,
border: { border: {
type: Boolean, type: Boolean,

View File

@ -19,7 +19,7 @@ export type CheckboxGroupToggleAllOptions =
export type CheckboxGroupProvide = CheckerParent & { export type CheckboxGroupProvide = CheckerParent & {
props: { props: {
max: number | string; max: number | string;
modelValue: any[]; modelValue: unknown[];
}; };
updateModelValue: (value: unknown[]) => void; updateModelValue: (value: unknown[]) => void;
}; };
@ -32,7 +32,7 @@ export default createComponent({
iconSize: [Number, String], iconSize: [Number, String],
checkedColor: String, checkedColor: String,
modelValue: { modelValue: {
type: Array as PropType<any[]>, type: Array as PropType<unknown[]>,
default: () => [], default: () => [],
}, },
}, },

View File

@ -1,5 +1,5 @@
import { ref, computed, defineComponent, PropType } from 'vue'; import { ref, computed, defineComponent, PropType } from 'vue';
import { addUnit } from '../utils'; import { addUnit, UnknownProp } from '../utils';
import Icon from '../icon'; import Icon from '../icon';
export type CheckerShape = 'square' | 'round'; export type CheckerShape = 'square' | 'round';
@ -15,10 +15,10 @@ export type CheckerParent = {
}; };
export const checkerProps = { export const checkerProps = {
name: null as any, name: UnknownProp,
disabled: Boolean, disabled: Boolean,
iconSize: [Number, String], iconSize: [Number, String],
modelValue: null as any, modelValue: UnknownProp,
checkedColor: String, checkedColor: String,
labelPosition: String as PropType<CheckerLabelPosition>, labelPosition: String as PropType<CheckerLabelPosition>,
labelDisabled: Boolean, labelDisabled: Boolean,

View File

@ -54,7 +54,7 @@ export default createComponent({
if (parent && props.bindGroup) { if (parent && props.bindGroup) {
return parent.props.modelValue.indexOf(props.name) !== -1; return parent.props.modelValue.indexOf(props.name) !== -1;
} }
return props.modelValue; return !!props.modelValue;
}); });
const toggle = (newValue = !checked.value) => { const toggle = (newValue = !checked.value) => {

View File

@ -4,6 +4,7 @@ exports[`should adjust label position when using label-position prop 1`] = `
<div role="checkbox" <div role="checkbox"
class="van-checkbox" class="van-checkbox"
tabindex="0" tabindex="0"
aria-checked="false"
> >
<span class="van-checkbox__label van-checkbox__label--left"> <span class="van-checkbox__label van-checkbox__label--left">
Label Label

View File

@ -1,7 +1,7 @@
import { PropType } from 'vue'; import { PropType } from 'vue';
// Utils // Utils
import { createNamespace } from '../utils'; import { createNamespace, UnknownProp } from '../utils';
import { RED } from '../utils/constant'; import { RED } from '../utils/constant';
// Components // Components
@ -25,7 +25,7 @@ export default createComponent({
props: { props: {
list: Array as PropType<ContactListItem[]>, list: Array as PropType<ContactListItem[]>,
addText: String, addText: String,
modelValue: null as any, modelValue: UnknownProp,
defaultTagText: String, defaultTagText: String,
}, },

View File

@ -2,7 +2,7 @@ import { PropType, reactive } from 'vue';
// Utils // Utils
import { callInterceptor, Interceptor } from '../utils/interceptor'; import { callInterceptor, Interceptor } from '../utils/interceptor';
import { createNamespace, addUnit, pick } from '../utils'; import { createNamespace, addUnit, pick, UnknownProp } from '../utils';
import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant';
// Components // Components
@ -32,7 +32,7 @@ export default createComponent({
message: String, message: String,
callback: Function as PropType<(action?: DialogAction) => void>, callback: Function as PropType<(action?: DialogAction) => void>,
allowHtml: Boolean, allowHtml: Boolean,
className: null, className: UnknownProp,
beforeClose: Function as PropType<Interceptor>, beforeClose: Function as PropType<Interceptor>,
messageAlign: String as PropType<DialogMessageAlign>, messageAlign: String as PropType<DialogMessageAlign>,
showCancelButton: Boolean, showCancelButton: Boolean,

View File

@ -1,4 +1,9 @@
import { App, TeleportProps } from 'vue'; import {
App,
CSSProperties,
TeleportProps,
ComponentPublicInstance,
} from 'vue';
import { inBrowser } from '../utils'; import { inBrowser } from '../utils';
import { Interceptor } from '../utils/interceptor'; import { Interceptor } from '../utils/interceptor';
import { mountComponent, usePopupState } from '../utils/mount-component'; import { mountComponent, usePopupState } from '../utils/mount-component';
@ -15,14 +20,14 @@ export type DialogOptions = {
message?: string; message?: string;
overlay?: boolean; overlay?: boolean;
teleport?: TeleportProps['to']; teleport?: TeleportProps['to'];
className?: any; className?: unknown;
allowHtml?: boolean; allowHtml?: boolean;
lockScroll?: boolean; lockScroll?: boolean;
transition?: string; transition?: string;
beforeClose?: Interceptor; beforeClose?: Interceptor;
messageAlign?: DialogMessageAlign; messageAlign?: DialogMessageAlign;
overlayClass?: string; overlayClass?: string;
overlayStyle?: Record<string, any>; overlayStyle?: CSSProperties;
closeOnPopstate?: boolean; closeOnPopstate?: boolean;
cancelButtonText?: string; cancelButtonText?: string;
showCancelButton?: boolean; showCancelButton?: boolean;
@ -33,8 +38,8 @@ export type DialogOptions = {
closeOnClickOverlay?: boolean; closeOnClickOverlay?: boolean;
}; };
// TODO remove any // eslint-disable-next-line
let instance: any; let instance: ComponentPublicInstance<{}, any>;
function initInstance() { function initInstance() {
const Wrapper = { const Wrapper = {
@ -82,7 +87,7 @@ Dialog.defaultOptions = {
transition: 'van-dialog-bounce', transition: 'van-dialog-bounce',
beforeClose: null, beforeClose: null,
overlayClass: '', overlayClass: '',
overlayStyle: null, overlayStyle: undefined,
messageAlign: '', messageAlign: '',
cancelButtonText: '', cancelButtonText: '',
cancelButtonColor: null, cancelButtonColor: null,

View File

@ -1,7 +1,7 @@
import { reactive, Teleport } from 'vue'; import { reactive, Teleport } from 'vue';
// Utils // Utils
import { createNamespace } from '../utils'; import { createNamespace, UnknownProp } from '../utils';
import { DROPDOWN_KEY } from '../dropdown-menu'; import { DROPDOWN_KEY } from '../dropdown-menu';
// Composition // Composition
@ -20,8 +20,8 @@ export default createComponent({
title: String, title: String,
disabled: Boolean, disabled: Boolean,
teleport: [String, Object], teleport: [String, Object],
modelValue: null, modelValue: UnknownProp,
titleClass: null, titleClass: UnknownProp,
options: { options: {
type: Array, type: Array,
default: () => [], default: () => [],

View File

@ -18,6 +18,7 @@ import {
isObject, isObject,
isPromise, isPromise,
isFunction, isFunction,
UnknownProp,
resetScroll, resetScroll,
formatNumber, formatNumber,
preventDefault, preventDefault,
@ -60,7 +61,7 @@ export default createComponent({
formatter: Function as PropType<(value: string) => string>, formatter: Function as PropType<(value: string) => string>,
maxlength: [Number, String], maxlength: [Number, String],
labelWidth: [Number, String], labelWidth: [Number, String],
labelClass: null as any, labelClass: UnknownProp,
labelAlign: String as PropType<FieldTextAlign>, labelAlign: String as PropType<FieldTextAlign>,
inputAlign: String as PropType<FieldTextAlign>, inputAlign: String as PropType<FieldTextAlign>,
placeholder: String, placeholder: String,

View File

@ -1,6 +1,7 @@
import { nextTick, onMounted, reactive, ref, watch } from 'vue'; import { nextTick, onMounted, reactive, ref, watch } from 'vue';
// Utils // Utils
import { UnknownProp } from '../utils';
import { bem, createComponent } from './shared'; import { bem, createComponent } from './shared';
import { callInterceptor } from '../utils/interceptor'; import { callInterceptor } from '../utils/interceptor';
@ -17,8 +18,8 @@ import ImagePreviewItem from './ImagePreviewItem';
export default createComponent({ export default createComponent({
props: { props: {
show: Boolean, show: Boolean,
className: null,
closeable: Boolean, closeable: Boolean,
className: UnknownProp,
beforeClose: Function, beforeClose: Function,
showIndicators: Boolean, showIndicators: Boolean,
images: { images: {

View File

@ -1,5 +1,11 @@
import { PropType, Transition, CSSProperties } from 'vue'; import { PropType, Transition, CSSProperties } from 'vue';
import { noop, isDef, preventDefault, createNamespace } from '../utils'; import {
noop,
isDef,
UnknownProp,
preventDefault,
createNamespace,
} from '../utils';
import { useLazyRender } from '../composables/use-lazy-render'; import { useLazyRender } from '../composables/use-lazy-render';
const [createComponent, bem] = createNamespace('overlay'); const [createComponent, bem] = createNamespace('overlay');
@ -9,7 +15,7 @@ export default createComponent({
show: Boolean, show: Boolean,
zIndex: [Number, String], zIndex: [Number, String],
duration: [Number, String], duration: [Number, String],
className: null, className: UnknownProp,
customStyle: Object as PropType<CSSProperties>, customStyle: Object as PropType<CSSProperties>,
lockScroll: { lockScroll: {
type: Boolean, type: Boolean,

View File

@ -3,7 +3,13 @@ import { ref, watch, reactive, PropType } from 'vue';
// Utils // Utils
import { deepClone } from '../utils/deep-clone'; import { deepClone } from '../utils/deep-clone';
import { range, isObject, createNamespace, preventDefault } from '../utils'; import {
range,
isObject,
UnknownProp,
preventDefault,
createNamespace,
} from '../utils';
// Composition // Composition
import { useParent } from '@vant/use'; import { useParent } from '@vant/use';
@ -42,7 +48,7 @@ export type PickerOption = string | PickerObjectOption;
export type PickerObjectColumn = { export type PickerObjectColumn = {
values?: PickerOption[]; values?: PickerOption[];
children?: PickerColumn; children?: PickerColumn;
className?: any; className?: unknown;
defaultIndex?: number; defaultIndex?: number;
// for custom filed names // for custom filed names
[key: string]: any; [key: string]: any;
@ -58,7 +64,7 @@ export default createComponent({
props: { props: {
readonly: Boolean, readonly: Boolean,
allowHtml: Boolean, allowHtml: Boolean,
className: String, className: UnknownProp,
textKey: { textKey: {
type: String, type: String,
required: true, required: true,

View File

@ -13,7 +13,7 @@ import {
onDeactivated, onDeactivated,
onBeforeUnmount, onBeforeUnmount,
} from 'vue'; } from 'vue';
import { createNamespace, isDef } from '../utils'; import { createNamespace, isDef, UnknownProp } from '../utils';
// Composition // Composition
import { useEventListener } from '@vant/use'; import { useEventListener } from '@vant/use';
@ -45,9 +45,9 @@ export const popupSharedProps = {
// teleport // teleport
teleport: [String, Object] as PropType<TeleportProps['to']>, teleport: [String, Object] as PropType<TeleportProps['to']>,
// overlay custom style // overlay custom style
overlayStyle: Object, overlayStyle: Object as PropType<CSSProperties>,
// overlay custom class name // overlay custom class name
overlayClass: null, overlayClass: UnknownProp,
// Initial rendering animation // Initial rendering animation
transitionAppear: Boolean, transitionAppear: Boolean,
// whether to show overlay // whether to show overlay

View File

@ -1,5 +1,5 @@
import { watch } from 'vue'; import { watch } from 'vue';
import { createNamespace } from '../utils'; import { UnknownProp, createNamespace } from '../utils';
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
import { useLinkField } from '../composables/use-link-field'; import { useLinkField } from '../composables/use-link-field';
import { CheckerParent } from '../checkbox/Checker'; import { CheckerParent } from '../checkbox/Checker';
@ -10,7 +10,7 @@ export const RADIO_KEY = 'vanRadio';
export type RadioGroupProvide = CheckerParent & { export type RadioGroupProvide = CheckerParent & {
props: { props: {
modelValue: any; modelValue: unknown;
}; };
updateModelValue: (value: unknown) => void; updateModelValue: (value: unknown) => void;
}; };
@ -20,7 +20,7 @@ export default createComponent({
disabled: Boolean, disabled: Boolean,
iconSize: [Number, String], iconSize: [Number, String],
direction: String, direction: String,
modelValue: null as any, modelValue: UnknownProp,
checkedColor: String, checkedColor: String,
}, },

View File

@ -1,4 +1,4 @@
import { createNamespace, addUnit } from '../utils'; import { createNamespace, addUnit, UnknownProp } from '../utils';
import { useLinkField } from '../composables/use-link-field'; import { useLinkField } from '../composables/use-link-field';
import Loading from '../loading'; import Loading from '../loading';
@ -9,15 +9,15 @@ export default createComponent({
size: [Number, String], size: [Number, String],
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
modelValue: null as any, modelValue: UnknownProp,
activeColor: String, activeColor: String,
inactiveColor: String, inactiveColor: String,
activeValue: { activeValue: {
type: null as any, type: UnknownProp,
default: true, default: true,
}, },
inactiveValue: { inactiveValue: {
type: null as any, type: UnknownProp,
default: false, default: false,
}, },
}, },

View File

@ -1,5 +1,5 @@
import { ref, watch, nextTick } from 'vue'; import { ref, watch, nextTick } from 'vue';
import { createNamespace } from '../utils'; import { createNamespace, UnknownProp } from '../utils';
import { TABS_KEY } from '../tabs'; import { TABS_KEY } from '../tabs';
// Composition // Composition
@ -18,9 +18,9 @@ export default createComponent({
name: [Number, String], name: [Number, String],
badge: [Number, String], badge: [Number, String],
title: String, title: String,
titleStyle: null,
titleClass: null,
disabled: Boolean, disabled: Boolean,
titleClass: UnknownProp,
titleStyle: null,
}, },
setup(props, { slots }) { setup(props, { slots }) {

View File

@ -1,7 +1,7 @@
import { watch, onMounted, onUnmounted, PropType } from 'vue'; import { watch, PropType, onMounted, onUnmounted, CSSProperties } from 'vue';
// Utils // Utils
import { createNamespace, isDef } from '../utils'; import { createNamespace, isDef, UnknownProp } from '../utils';
import { lockClick } from './lock-click'; import { lockClick } from './lock-click';
// Components // Components
@ -19,13 +19,13 @@ export default createComponent({
icon: String, icon: String,
show: Boolean, show: Boolean,
message: [Number, String], message: [Number, String],
className: null, className: UnknownProp,
iconPrefix: String, iconPrefix: String,
lockScroll: Boolean, lockScroll: Boolean,
loadingType: String as PropType<LoadingType>, loadingType: String as PropType<LoadingType>,
forbidClick: Boolean, forbidClick: Boolean,
overlayClass: null, overlayClass: UnknownProp,
overlayStyle: Object, overlayStyle: Object as PropType<CSSProperties>,
closeOnClick: Boolean, closeOnClick: Boolean,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
type: { type: {

View File

@ -15,13 +15,13 @@ export type ToastOptions = {
duration?: number; duration?: number;
teleport?: TeleportProps['to']; teleport?: TeleportProps['to'];
position?: ToastPosition; position?: ToastPosition;
className?: any; className?: unknown;
transition?: string; transition?: string;
iconPrefix?: string; iconPrefix?: string;
loadingType?: LoadingType; loadingType?: LoadingType;
forbidClick?: boolean; forbidClick?: boolean;
closeOnClick?: boolean; closeOnClick?: boolean;
overlayClass?: any; overlayClass?: unknown;
overlayStyle?: Record<string, any>; overlayStyle?: Record<string, any>;
closeOnClickOverlay?: boolean; closeOnClickOverlay?: boolean;
}; };

View File

@ -22,7 +22,7 @@ export type TreeSelectItem = {
badge?: number | string; badge?: number | string;
children?: TreeSelectChild[]; children?: TreeSelectChild[];
disabled?: boolean; disabled?: boolean;
className?: any; className?: unknown;
}; };
export default createComponent({ export default createComponent({

View File

@ -1,8 +1,13 @@
import { PropType } from 'vue';
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop() {} export function noop() {}
export const inBrowser = typeof window !== 'undefined'; export const inBrowser = typeof window !== 'undefined';
// unknown type for Vue prop
export const UnknownProp = (null as unknown) as PropType<unknown>;
export function isDef<T>(val: T): val is NonNullable<T> { export function isDef<T>(val: T): val is NonNullable<T> {
return val !== undefined && val !== null; return val !== undefined && val !== null;
} }