Skip to content

Commit

Permalink
Improve typing for Vue
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Dec 29, 2023
1 parent ca639e3 commit 9782943
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 6 additions & 9 deletions src/vue/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource vue */
import { ref, defineComponent, watch } from "vue";
import { ref, defineComponent, watch, StyleValue, PropType, VNode } from "vue";
import { ItemResizeObserver } from "../core/resizer";
import { isRTLDocument } from "../core/environment";

Expand All @@ -8,8 +8,8 @@ import { isRTLDocument } from "../core/environment";
*/
export const ListItem = /*#__PURE__*/ defineComponent({
props: {
_children: { type: Object, required: true },
_resizer: { type: Object, required: true },
_children: { type: Object as PropType<VNode>, required: true },
_resizer: { type: Object as PropType<ItemResizeObserver>, required: true },
_index: { type: Number, required: true },
_offset: { type: Number, required: true },
_hide: { type: Boolean },
Expand All @@ -23,10 +23,7 @@ export const ListItem = /*#__PURE__*/ defineComponent({
watch(
() => elementRef.value && props._index,
(_, __, onCleanup) => {
const cleanupObserver = (props._resizer as ItemResizeObserver)(
elementRef.value!,
props._index
);
const cleanupObserver = props._resizer(elementRef.value!, props._index);
onCleanup(cleanupObserver);
},
{
Expand All @@ -43,7 +40,7 @@ export const ListItem = /*#__PURE__*/ defineComponent({
_isHorizontal: isHorizontal,
} = props as Omit<typeof props, "_element"> & { _element: "div" };

const style: Record<string, number | string> = {
const style: StyleValue = {
margin: 0,
padding: 0,
position: "absolute",
Expand All @@ -54,7 +51,7 @@ export const ListItem = /*#__PURE__*/ defineComponent({
visibility: hide ? "hidden" : "visible",
};
if (isHorizontal) {
style["display"] = "flex";
style.display = "flex";
}

return (
Expand Down
8 changes: 4 additions & 4 deletions src/vue/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const VList = /*#__PURE__*/ defineComponent({
const isHorizontal = props.horizontal;
const rootRef = ref<HTMLDivElement>();
const store = createVirtualStore(
props.data!.length,
props.data.length,
props.initialItemSize ?? 40,
undefined,
undefined,
Expand Down Expand Up @@ -137,7 +137,7 @@ export const VList = /*#__PURE__*/ defineComponent({
});

watch(
() => props.data!.length,
() => props.data.length,
(count) => {
store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);
}
Expand Down Expand Up @@ -184,7 +184,7 @@ export const VList = /*#__PURE__*/ defineComponent({
return () => {
rerender.value;

const count = props.data!.length;
const count = props.data.length;

const [startIndex, endIndex] = store._getRange();
const scrollDirection = store._getScrollDirection();
Expand All @@ -204,7 +204,7 @@ export const VList = /*#__PURE__*/ defineComponent({

const items: VNode[] = [];
for (let i = overscanedStartIndex; i <= overscanedEndIndex; i++) {
const e = slots.default(props.data![i]!)[0]!;
const e = slots.default(props.data![i]!)[0]! as VNode
const key = e.key;
items.push(
<ListItem
Expand Down

0 comments on commit 9782943

Please sign in to comment.