From 7ec644c3bc8321ab4abb2f4bbe21c4aa49965727 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 12 Feb 2021 20:22:21 +0800 Subject: [PATCH] types(ContactList): use tsx (#8146) --- .../{index.spec.js.snap => index.spec.ts.snap} | 0 .../test/{index.spec.js => index.spec.ts} | 0 src/contact-list/{index.js => index.tsx} | 17 +++++++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) rename src/contact-edit/test/__snapshots__/{index.spec.js.snap => index.spec.ts.snap} (100%) rename src/contact-edit/test/{index.spec.js => index.spec.ts} (100%) rename src/contact-list/{index.js => index.tsx} (85%) diff --git a/src/contact-edit/test/__snapshots__/index.spec.js.snap b/src/contact-edit/test/__snapshots__/index.spec.ts.snap similarity index 100% rename from src/contact-edit/test/__snapshots__/index.spec.js.snap rename to src/contact-edit/test/__snapshots__/index.spec.ts.snap diff --git a/src/contact-edit/test/index.spec.js b/src/contact-edit/test/index.spec.ts similarity index 100% rename from src/contact-edit/test/index.spec.js rename to src/contact-edit/test/index.spec.ts diff --git a/src/contact-list/index.js b/src/contact-list/index.tsx similarity index 85% rename from src/contact-list/index.js rename to src/contact-list/index.tsx index aef9e6bbc..7a8e52518 100644 --- a/src/contact-list/index.js +++ b/src/contact-list/index.tsx @@ -1,3 +1,5 @@ +import { PropType } from 'vue'; + // Utils import { createNamespace } from '../utils'; import { RED } from '../utils/constant'; @@ -12,18 +14,25 @@ import RadioGroup from '../radio-group'; const [createComponent, bem, t] = createNamespace('contact-list'); +export type ContactListItem = { + id?: number | string; + tel: number | string; + name: string; + isDefault?: boolean; +}; + export default createComponent({ props: { - list: Array, + list: Array as PropType, addText: String, - modelValue: null, + modelValue: null as any, defaultTagText: String, }, emits: ['add', 'edit', 'select', 'update:modelValue'], setup(props, { emit }) { - const renderItem = (item, index) => { + const renderItem = (item: ContactListItem, index: number) => { const onClick = () => { emit('update:modelValue', item.id); emit('select', item, index); @@ -45,7 +54,7 @@ export default createComponent({ ); const renderContent = () => { - const nodes = [`${item.name},${item.tel}`]; + const nodes: JSX.Element[] = [`${item.name},${item.tel}`]; if (item.isDefault && props.defaultTagText) { nodes.push(