api-typings
api-typings copied to clipboard
[Feature request] Update api generation
Ts 4.4 introduce a new flag --exactOptionalPropertyTypes, and it's already on stable channel.
See https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types
With this option,
interface Person {
name: string,
age?: number | undefined;
}
and
interface Person {
name: string,
age?: number;
}
won't be the same.
Which means all the opitional option should be extra announced with | undefined if it could be. Other wise code like following will be regarded as an error with --exactOptionalPropertyTypes
E.g.: we can pass title: undefined to the following api
let title: string | undefined;
// somehow set title only in some condfitions
wx.showLoading({ title });
// 不能将类型“string | undefined”分配给类型“string”。
// 不能将类型“undefined”分配给类型“string”。ts(2322)
So we should generate the option to:
// before
interface ShowLoadingOption {
/** 提示的内容 */
title: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ShowLoadingCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ShowLoadingFailCallback
/** 是否显示透明蒙层,防止触摸穿透 */
mask?: boolean
/** 接口调用成功的回调函数 */
success?: ShowLoadingSuccessCallback
}
// after
interface ShowLoadingOption {
/** 提示的内容 */
title: string | undefined
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ShowLoadingCompleteCallback | undefined
/** 接口调用失败的回调函数 */
fail?: ShowLoadingFailCallback | undefined
/** 是否显示透明蒙层,防止触摸穿透 */
mask?: boolean | undefined
/** 接口调用成功的回调函数 */
success?: ShowLoadingSuccessCallback | undefined
}