types: fix typing issues

This commit is contained in:
chenjiahan 2021-04-29 20:56:40 +08:00
parent f96bc10158
commit 51aff18dea
10 changed files with 22 additions and 16 deletions

View File

@ -102,7 +102,7 @@ VantComponent({
onChange(event: WechatMiniprogram.CustomEvent) { onChange(event: WechatMiniprogram.CustomEvent) {
const { index, picker, value } = event.detail; const { index, picker, value } = event.detail;
this.code = value[index].code; this.code = value[index].code;
this.setValues().then(() => { this.setValues()?.then(() => {
this.$emit('change', { this.$emit('change', {
picker, picker,
values: this.parseValues(picker.getValues()), values: this.parseValues(picker.getValues()),

View File

@ -10,7 +10,7 @@ interface Day {
date: Date; date: Date;
type: string; type: string;
text: number; text: number;
bottomInfo: string; bottomInfo?: string;
} }
VantComponent({ VantComponent({
@ -125,13 +125,13 @@ VantComponent({
getRangeDayType(day) { getRangeDayType(day) {
const { currentDate, allowSameDay } = this.data; const { currentDate, allowSameDay } = this.data;
if (!Array.isArray(currentDate)) { if (!Array.isArray(currentDate)) {
return; return '';
} }
const [startDay, endDay] = currentDate; const [startDay, endDay] = currentDate;
if (!startDay) { if (!startDay) {
return; return '';
} }
const compareToStart = compareDay(day, startDay); const compareToStart = compareDay(day, startDay);
@ -157,6 +157,8 @@ VantComponent({
if (compareToStart > 0 && compareToEnd < 0) { if (compareToStart > 0 && compareToEnd < 0) {
return 'middle'; return 'middle';
} }
return '';
}, },
getDayType(day) { getDayType(day) {
@ -178,6 +180,8 @@ VantComponent({
if (type === 'range') { if (type === 'range') {
return this.getRangeDayType(day); return this.getRangeDayType(day);
} }
return '';
}, },
getBottomInfo(type) { getBottomInfo(type) {

View File

@ -272,7 +272,7 @@ VantComponent({
} }
}, },
select(date, complete) { select(date, complete?: boolean) {
if (complete && this.data.type === 'range') { if (complete && this.data.type === 'range') {
const valid = this.checkRange(date); const valid = this.checkRange(date);

View File

@ -68,7 +68,7 @@ VantComponent({
}, },
methods: { methods: {
getContext() { getContext(): Promise<WechatMiniprogram.CanvasContext> {
const { type, size } = this.data; const { type, size } = this.data;
if (type === '' || !canIUseCanvas2d()) { if (type === '' || !canIUseCanvas2d()) {
@ -108,7 +108,10 @@ VantComponent({
Object.keys(color) Object.keys(color)
.sort((a, b) => parseFloat(a) - parseFloat(b)) .sort((a, b) => parseFloat(a) - parseFloat(b))
.map((key) => .map((key) =>
LinearColor.addColorStop(parseFloat(key) / 100, color[key]) LinearColor.addColorStop(
parseFloat(key) / 100,
color[key] as string
)
); );
this.hoverColor = LinearColor; this.hoverColor = LinearColor;
}); });
@ -118,7 +121,7 @@ VantComponent({
return Promise.resolve(); return Promise.resolve();
}, },
presetCanvas(context, strokeStyle, beginAngle, endAngle, fill) { presetCanvas(context, strokeStyle, beginAngle, endAngle, fill?: string) {
const { strokeWidth, lineCap, clockwise, size } = this.data; const { strokeWidth, lineCap, clockwise, size } = this.data;
const position = size / 2; const position = size / 2;
const radius = position - strokeWidth / 2; const radius = position - strokeWidth / 2;

View File

@ -15,7 +15,7 @@ export function nextTick(cb: (...args: any[]) => void) {
} }
} }
let systemInfo: WechatMiniprogram.GetSystemInfoSyncResult; let systemInfo: WechatMiniprogram.SystemInfo;
export function getSystemInfoSync() { export function getSystemInfoSync() {
if (systemInfo == null) { if (systemInfo == null) {
systemInfo = wx.getSystemInfoSync(); systemInfo = wx.getSystemInfoSync();

View File

@ -145,9 +145,8 @@ VantComponent({
const { filter } = this.data; const { filter } = this.data;
const results = this.getRanges().map(({ type, range }) => { const results = this.getRanges().map(({ type, range }) => {
let values = times(range[1] - range[0] + 1, (index) => { let values = times(range[1] - range[0] + 1, (index) => {
let value = range[0] + index; const value = range[0] + index;
value = type === 'year' ? `${value}` : padZero(value); return type === 'year' ? `${value}` : padZero(value);
return value;
}); });
if (filter) { if (filter) {

View File

@ -113,7 +113,7 @@ VantComponent({
: option; : option;
}, },
setIndex(index: number, userAction: boolean) { setIndex(index: number, userAction?: boolean) {
const { data } = this; const { data } = this;
index = this.adjustIndex(index) || 0; index = this.adjustIndex(index) || 0;
const offset = -index * data.itemHeight; const offset = -index * data.itemHeight;

View File

@ -89,7 +89,7 @@ VantComponent({
}); });
}, },
updateValue(value: number, end: boolean, drag: boolean) { updateValue(value: number, end?: boolean, drag?: boolean) {
value = this.format(value); value = this.format(value);
const { min } = this.data; const { min } = this.data;
const width = `${((value - min) * 100) / this.getRange()}%`; const width = `${((value - min) * 100) / this.getRange()}%`;

View File

@ -51,7 +51,7 @@ VantComponent({
}, },
methods: { methods: {
onScroll({ scrollTop } = {}) { onScroll({ scrollTop }: { scrollTop?: number } = {}) {
const { container, offsetTop, disabled } = this.data; const { container, offsetTop, disabled } = this.data;
if (disabled) { if (disabled) {

View File

@ -82,7 +82,7 @@ VantComponent({
this.setData({ lists, isInCount: lists.length < maxCount }); this.setData({ lists, isInCount: lists.length < maxCount });
}, },
getDetail(index) { getDetail(index?: number) {
return { return {
name: this.data.name, name: this.data.name,
index: index == null ? this.data.fileList.length : index, index: index == null ? this.data.fileList.length : index,