Merge pull request #26484 from Jimexist/add-wepy

add typing for wepy
This commit is contained in:
Nathan Shively-Sanders
2018-06-20 10:34:12 -07:00
committed by GitHub
12 changed files with 587 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
export interface AppConfig {
appEvents?: string[];
pageEvents?: string[];
noPromiseAPI?: string[] | { [name: string]: boolean };
}
export interface AppConstructor {
new (): app;
}
export default class app {
$init(wepy: any, config: AppConfig): any;
}
+12
View File
@@ -0,0 +1,12 @@
import page, { PageConstructor } from "./page";
import app, { AppConstructor, AppConfig } from "./app";
declare const defaultExport: {
$createApp?: (appClass: AppConstructor, appConfig: AppConfig) => app;
$createPage?: (
pageClass: PageConstructor,
pagePath: string | boolean
) => page;
};
export default defaultExport;
+20
View File
@@ -0,0 +1,20 @@
import event from "./event";
export default class component {
$isComponent: boolean;
$prefix: string;
data: { [name: string]: any };
computed?: { [name: string]: (self?: component) => any };
methods?: { [name: string]: (evt?: event) => any };
$init($wxpage: any, $root: any, $parent: any): void;
$initMixins(): void;
onLoad(): void;
setData(k: string | string[], v: any): void;
getWxPage(): any;
$setIndex(index: number): void;
$getComponent(com: any): any;
$apply(fn: () => void): void;
$nextTick(fn: () => void): void;
}
+6
View File
@@ -0,0 +1,6 @@
export default class event {
active: boolean;
constructor(name: string, source: any, type: any);
$destroy(): void;
$transfor(wxevent: any[]): void;
}
+35
View File
@@ -0,0 +1,35 @@
// Type definitions for wepy 1.7
// Project: https://github.com/Tencent/wepy#readme
// Definitions by: Jiayu Liu <https://github.com/Jimexist>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import component from "./component";
import mixin from "./mixin";
import event from "./event";
import page from "./page";
import app from "./app";
import util from "./util";
import base from "./base";
import { WxEnhances } from "./wx_enhanced";
interface DefaultExport extends WxEnhances {
event: typeof event;
app: typeof app;
component: typeof component;
page: typeof page;
mixin: typeof mixin;
$createApp: typeof base.$createApp;
$createPage: typeof base.$createPage;
$isEmpty: typeof util.$isEmpty;
$isEqual: typeof util.$isEqual;
$isDeepEqual: typeof util.$isDeepEqual;
$has: typeof util.$has;
$extend: typeof util.$extend;
$isPlainObject: typeof util.$isPlainObject;
$copy: typeof util.$copy;
}
declare const defaultExport: DefaultExport;
export default defaultExport;
+1
View File
@@ -0,0 +1 @@
export default class mixin {}
+23
View File
@@ -0,0 +1,23 @@
import component from "./component";
export interface UrlParam {
url: string;
}
export interface PageConstructor {
new (): page;
}
export default class page extends component {
$preloadData: { [key: string]: any };
$init(wxpage: any, $parent: any): any;
$route(
type: "redirectTo" | "navigateTo",
url: string | UrlParam,
params?: { [name: string]: any }
): any;
$preload(key: string | { [key: string]: any }, data: any): any;
$switch(url: string | UrlParam): any;
$redirect(url: string, params?: object): any;
$back(delta: number | { delta: number }): any;
}
+27
View File
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"app.d.ts",
"base.d.ts",
"component.d.ts",
"event.d.ts",
"index.d.ts",
"mixin.d.ts",
"page.d.ts",
"util.d.ts",
"wx_enhanced.d.ts",
"wepy-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
+15
View File
@@ -0,0 +1,15 @@
declare const defaultExport: {
$isEmpty: (obj: object) => boolean;
$isEqual: (a: any, b: any, aStack?: any[], bStack?: any[]) => boolean;
$isDeepEqual: (a: any, b: any, aStack?: any[], bStack?: any[]) => boolean;
$has: (obj: object, path: string) => boolean;
$extend: () => any;
$copy: <T>(obj: T, deep?: boolean) => T;
$isPlainObject: (obj: any) => boolean;
$resolvePath: (route: string, url: string) => string;
$getParams: (url: string) => object;
hyphenate: (str: string) => string;
camelize: (str: string) => string;
};
export default defaultExport;
+41
View File
@@ -0,0 +1,41 @@
import wepy from "wepy";
export class MyComponent extends wepy.component {
data = {
reveal: false,
img: "",
animationData: "",
imgClassName: "",
imgMode: "scaleToFill",
title: "loading",
titleClassName: ""
};
methods = {};
onLoad() {
super.onLoad();
}
}
export class BindJwc extends wepy.page {
config = {
navigationBarTitleText: "校历",
enablePullDownRefresh: true
};
mixins = [];
data = {};
computed = {
termName(): number {
return 1;
}
};
methods = {
returnToday(): number {
return 123;
}
};
init() {}
async onLoad() {}
}
+391
View File
@@ -0,0 +1,391 @@
export interface WechatProfileDetails {
photoFilePath?: string;
nickName?: string;
lastName?: string;
middleName?: string;
firstName?: string;
remark?: string;
mobilePhoneNumber?: string;
email?: string;
url?: string;
workAddressCountry?: string;
workAddressState?: string;
workAddressCity?: string;
workAddressStreet?: string;
workAddressPostalCode?: string;
homeFaxNumber?: string;
homePhoneNumber?: string;
homeAddressCountry?: string;
homeAddressState?: string;
homeAddressCity?: string;
homeAddressStreet?: string;
homeAddressPostalCode?: string;
}
export interface RotateAnimation {
rotate(deg: number): Animation;
rotateX(deg: number): Animation;
rotateY(deg: number): Animation;
rotateZ(deg: number): Animation;
rotate3d(): Animation;
}
export interface ScaleAnimation {
scale(sx: number): Animation;
scaleX(sx: number): Animation;
scaleY(sy: number): Animation;
scaleZ(sz: number): Animation;
scale3d(): Animation;
}
export interface TranslateAnimation {
translate(tx: number): Animation;
translateX(tx: number): Animation;
translateY(ty: number): Animation;
translateZ(tz: number): Animation;
translate3d(): Animation;
}
export interface SkewAnimation {
skew(ax: number): Animation;
skewX(ax: number): Animation;
skewY(ay: number): Animation;
}
export interface Animation
extends RotateAnimation,
ScaleAnimation,
SkewAnimation,
TranslateAnimation {
opacity(x: number): Animation;
backgroundColor(x: string): Animation;
width(x: number): Animation;
height(x: number): Animation;
top(x: number): Animation;
left(x: number): Animation;
bottom(x: number): Animation;
right(x: number): Animation;
}
export interface LagLng {
latitude: number;
longitude: number;
}
export type CallbackFunction<T> = (
callbacks: {
success: (res: T) => void;
fail: () => void;
complete: () => void;
}
) => void;
export interface MapContext {
getCenterLocation: CallbackFunction<LagLng>;
moveToLocation(): void;
translateMarker(params: {
markerId: number;
autoRotate: boolean;
duration: number;
destination: LagLng;
animationEnd: () => void;
}): void;
includePoints(params: { padding: number[]; points: LagLng[] }): void;
getRegion: CallbackFunction<{ southwest: LagLng; northeast: LagLng }>;
getScale: CallbackFunction<{ scale: number }>;
}
export interface UserInfo {
nickName: string;
avatarUrl: string;
gender: string;
city: string;
province: string;
country: string;
language: string;
}
export interface UrlParam {
url: string;
}
export interface FilePathParam {
filePath: string;
}
// WePY enhanced Wx interfaces and methods below are all accessible
export interface WxEnhances {
addPhoneContact(param: WechatProfileDetails): Promise<void>;
authorize(param: { scope: string }): Promise<any>;
canIUse(name: string): Promise<boolean>;
canvasGetImageData(
params: {
canvasId: string;
x: number;
y: number;
width: number;
height: number;
},
context: any
): Promise<{
width: number;
height: number;
data: Uint8ClampedArray;
}>;
canvasPutImageData(
params: {
canvasId: string;
data: Uint8ClampedArray;
x: number;
y: number;
height?: number;
wdith: number;
},
context: any
): Promise<void>;
canvasToTempFilePath(
params: {
x: number;
y: number;
width: number;
height: number;
destWidth: number;
destHeight: number;
canvasId: string;
},
context: any
): Promise<{ tempFilePath: string }>;
checkIsSoterEnrolledInDevice(params: {
checkAuthMode: "fingerPrint" | "facial" | "speech";
}): Promise<{
isEnrolled: boolean;
errMsg: string;
}>;
checkIsSupportSoterAuthentication(): Promise<{
supportMode: string[];
}>;
checkSession(): Promise<void>;
chooseInvoiceTitle(): Promise<{
type: "0" | "1";
title: string;
taxNumber: string;
companyAddress: string;
telephone: string;
bankName: string;
bankAccount: string;
errMsg: string;
}>;
chooseLocation(): Promise<{
name: string;
address: string;
latitude: number;
longitude: number;
}>;
chooseVideo(params: {
sourceType: string[];
compressed: boolean;
maxDuration: number;
}): Promise<{
tempFilePath: string;
duration: number;
size: number;
height: number;
width: number;
}>;
clearStorage(): Promise<void>;
createAnimation(params: {
duration: number;
timingFunction: string;
delay: number;
transformOrigin: string;
}): Promise<Animation>;
createCanvasContext(canvasId: string, context: any): Promise<void>;
createMapContext(mapId: string, context: any): MapContext;
createSelectorQuery(): Promise<{}>;
getLocation(params: {
type: string;
altitude: boolean;
}): Promise<{
latitude: number;
longitude: number;
speed: number;
accuracy: number;
altitude: number;
verticalAccuracy: number;
horizontalAccuracy: number;
}>;
getNetworkType(): Promise<{ networkType: string }>;
getSavedFileInfo(
params: FilePathParam
): Promise<{
errMsg: string;
size: number;
createTime: number;
}>;
getSavedFileList(): Promise<{
errMsg: string;
fileList: object[];
}>;
getSetting(): Promise<{
authSetting: {
"scope.userInfo": boolean;
"scope.userLocation": boolean;
"scope.address": boolean;
"scope.invoiceTitle": boolean;
"scope.werun": boolean;
"scope.record": boolean;
"scope.writePhotosAlbum": boolean;
"scope.camera": boolean;
};
}>;
getShareInfo(params: {
shareTicket: string;
timeout: number;
}): Promise<{
errMsg: string;
encryptedData: string;
iv: string;
}>;
getSystemInfo(): Promise<{
brand: string;
model: string;
pixelRatio: number;
screenWidth: number;
screenHeight: number;
windowWidth: number;
windowHeight: number;
statusBarHeight: number;
language: string;
version: string;
system: string;
platform: string;
fontSizeSetting: string;
SDKVersion: string;
}>;
getUserInfo(params: {
withCredentials: boolean;
lang: string;
timeout: number;
}): Promise<{
userInfo: object;
rawData: string;
signature: string;
encryptedData: string;
iv: string;
}>;
hideLoading(): Promise<void>;
hideNavigationBarLoading(): Promise<void>;
makePhoneCall(params: { phoneNumber: string }): Promise<void>;
navigateTo(params: UrlParam): Promise<void>;
onUserCaptureScreen(): Promise<void>;
openLocation(params: {
latitude: number;
longitude: number;
scale?: number;
name?: string;
address?: string;
}): Promise<void>;
pageScrollTo(params: {
scrollTop: number;
duration: number;
}): Promise<void>;
redirectTo(params: UrlParam): Promise<void>;
removeSavedFile(params: FilePathParam): Promise<void>;
removeStorage(params: { key: string }): Promise<void>;
request(params: UrlParam): Promise<any>;
requestPayment(params: {
timeStamp: string;
nonceStr: string;
package: string;
signType: string;
paySign: string;
}): Promise<void>;
scanCode(params: {
onlyFromCamera?: boolean;
scanType?: string[];
}): Promise<{
result: string;
scanType: string;
charSet: string;
path: string;
}>;
setNavigationBarAlpha(params: { alpha: number }): Promise<void>;
setNavigationBarColor(params: { color: number }): Promise<void>;
setNavigationBarTitle(params: { title: string }): Promise<void>;
setStorage(params: { key: string; data: string | object }): Promise<void>;
showActionSheet(params: {
itemList: string[];
itemColor: string;
}): Promise<void>;
showLoading(params: { title: string }): Promise<void>;
showModal(params: {
title: string;
content: string;
showCancel?: boolean;
cancelText?: string;
cancelColor?: string;
confirmText?: string;
confirmColor?: string;
}): Promise<{ confirm: boolean; cancel: boolean }>;
showNavigationBarLoading(): Promise<void>;
showToast(params: {
title: string;
icon?: "success" | "loading" | "none";
image?: string;
duration?: number;
mask?: boolean;
}): Promise<void>;
switchTab(params: UrlParam): Promise<void>;
}