types: reduce non-null assertion (#9355)

* types: reduce non-null assertion

* chore: upd

* chore: fix typing
This commit is contained in:
neverland 2021-08-30 20:35:29 +08:00 committed by GitHub
parent 140fa0c180
commit 4f393c93a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 62 additions and 71 deletions

View File

@ -41,9 +41,7 @@ export default defineComponent({
emit('input', `${express.address || ''} ${express.name || ''}`.trim()); emit('input', `${express.address || ''} ${express.name || ''}`.trim());
}; };
const onFinish = () => { const onFinish = () => field.value?.blur();
field.value!.blur();
};
const renderFinish = () => { const renderFinish = () => {
if (props.value && props.focused && android) { if (props.value && props.focused && android) {

View File

@ -285,8 +285,10 @@ export default defineComponent({
state.code = values[index].code; state.code = values[index].code;
setValues(); setValues();
const parsedValues = parseValues(pickerRef.value!.getValues()); if (pickerRef.value) {
const parsedValues = parseValues(pickerRef.value.getValues());
emit('change', parsedValues, index); emit('change', parsedValues, index);
}
}; };
const onConfirm = (values: AreaColumnOption[], index: number) => { const onConfirm = (values: AreaColumnOption[], index: number) => {

View File

@ -94,12 +94,14 @@ export default defineComponent({
const scrollIntoView = (body: Element) => { const scrollIntoView = (body: Element) => {
const el = props.showSubtitle ? daysRef.value : monthRef.value; const el = props.showSubtitle ? daysRef.value : monthRef.value;
if (el) {
const scrollTop = const scrollTop =
el!.getBoundingClientRect().top - el.getBoundingClientRect().top -
body.getBoundingClientRect().top + body.getBoundingClientRect().top +
body.scrollTop; body.scrollTop;
setScrollTop(body, scrollTop); setScrollTop(body, scrollTop);
}
}; };
const getMultipleDayType = (day: Date) => { const getMultipleDayType = (day: Date) => {

View File

@ -61,8 +61,8 @@ export default defineComponent({
const onTransitionEnd = () => { const onTransitionEnd = () => {
if (!expanded.value) { if (!expanded.value) {
show.value = false; show.value = false;
} else { } else if (wrapperRef.value) {
wrapperRef.value!.style.height = ''; wrapperRef.value.style.height = '';
} }
}; };

View File

@ -4,11 +4,11 @@ import { Ref, ref, onMounted, nextTick } from 'vue';
export const useHeight = (element: Element | Ref<Element | undefined>) => { export const useHeight = (element: Element | Ref<Element | undefined>) => {
const height = ref<number>(); const height = ref<number>();
onMounted(() => { onMounted(() =>
nextTick(() => { nextTick(() => {
height.value = useRect(element).height; height.value = useRect(element).height;
}); })
}); );
return height; return height;
}; };

View File

@ -71,17 +71,9 @@ export function useLockScroll(
} }
}; };
const init = () => { const init = () => shouldLock() && lock();
if (shouldLock()) {
lock();
}
};
const destroy = () => { const destroy = () => shouldLock() && unlock();
if (shouldLock()) {
unlock();
}
};
onMountedOrActivated(init); onMountedOrActivated(init);
onDeactivated(destroy); onDeactivated(destroy);

View File

@ -54,11 +54,10 @@ export default defineComponent({
} }
}; };
const onDelete = () => { const onDelete = () =>
Dialog.confirm({ Dialog.confirm({
title: t('confirmDelete'), title: t('confirmDelete'),
}).then(() => emit('delete', contact)); }).then(() => emit('delete', contact));
};
const renderButtons = () => ( const renderButtons = () => (
<div class={bem('buttons')}> <div class={bem('buttons')}>

View File

@ -222,7 +222,7 @@ export default defineComponent({
}); });
nextTick(() => { nextTick(() => {
picker.value!.setValues(values); picker.value?.setValues(values);
}); });
}; };

View File

@ -106,7 +106,7 @@ export default defineComponent({
]; ];
nextTick(() => { nextTick(() => {
picker.value!.setValues(values); picker.value?.setValues(values);
}); });
}; };

View File

@ -23,17 +23,14 @@ export default defineComponent({
}), }),
setup(props, { slots }) { setup(props, { slots }) {
return () => { return () => (
const style = {
color: props.color,
background: props.background,
};
return (
<Popup <Popup
show={props.show} show={props.show}
class={[bem([props.type]), props.className]} class={[bem([props.type]), props.className]}
style={style} style={{
color: props.color,
background: props.background,
}}
overlay={false} overlay={false}
position="top" position="top"
duration={0.2} duration={0.2}
@ -42,6 +39,5 @@ export default defineComponent({
{slots.default ? slots.default() : props.message} {slots.default ? slots.default() : props.message}
</Popup> </Popup>
); );
};
}, },
}); });

View File

@ -79,7 +79,7 @@ export default defineComponent({
closeOnClickOverlay: truthProp, closeOnClickOverlay: truthProp,
closeOnClickOutside: truthProp, closeOnClickOutside: truthProp,
offset: { offset: {
type: (Array as unknown) as PropType<[number, number]>, type: Array as unknown as PropType<[number, number]>,
default: () => [0, 8], default: () => [0, 8],
}, },
theme: { theme: {
@ -112,8 +112,9 @@ export default defineComponent({
const wrapperRef = ref<HTMLElement>(); const wrapperRef = ref<HTMLElement>();
const popoverRef = ref<ComponentInstance>(); const popoverRef = ref<ComponentInstance>();
const createPopperInstance = () => const createPopperInstance = () => {
createPopper(wrapperRef.value!, popoverRef.value!.popupRef.value, { if (wrapperRef.value && popoverRef.value) {
return createPopper(wrapperRef.value, popoverRef.value.popupRef.value, {
placement: props.placement, placement: props.placement,
modifiers: [ modifiers: [
{ {
@ -130,6 +131,9 @@ export default defineComponent({
}), }),
], ],
}); });
}
return null;
};
const updateLocation = () => { const updateLocation = () => {
nextTick(() => { nextTick(() => {

View File

@ -78,9 +78,7 @@ export default defineComponent({
} }
}; };
const clearTimer = () => { const clearTimer = () => clearTimeout(timer);
clearTimeout(timer);
};
const renderIcon = () => { const renderIcon = () => {
const { icon, type, iconSize, iconPrefix, loadingType } = props; const { icon, type, iconSize, iconPrefix, loadingType } = props;

View File

@ -155,7 +155,7 @@ Toast.clear = (all?: boolean) => {
} else if (!allowMultiple) { } else if (!allowMultiple) {
queue[0].clear(); queue[0].clear();
} else { } else {
queue.shift()!.clear(); queue.shift()?.clear();
} }
} }
}; };