Skip to content

Commit b9ea826

Browse files
author
boquanfu
committed
build: change miniprogram typings from @types to miniprogram-api-typings (#102)
1 parent 1199d6a commit b9ea826

10 files changed

+7686
-17416
lines changed

dist/index.js

+1-534
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+7,568-16,784
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"eslint-plugin-node": "^11.1.0",
4646
"eslint-plugin-prettier": "^5.1.3",
4747
"eslint-plugin-promise": "^6.2.0",
48-
"glass-easel": "0.5.4",
49-
"glass-easel-miniprogram-adapter": "0.5.4",
50-
"glass-easel-template-compiler": "0.5.4",
48+
"glass-easel": "~0.10.0",
49+
"glass-easel-miniprogram-adapter": "~0.10.0",
50+
"glass-easel-template-compiler": "~0.10.0",
5151
"gulp": "^5.0.0",
5252
"gulp-clean": "^0.4.0",
5353
"gulp-esbuild": "^0.12.0",
@@ -64,8 +64,8 @@
6464
"typescript": "^5.4.5"
6565
},
6666
"dependencies": {
67-
"@types/wechat-miniprogram": "^3.4.7",
6867
"fast-deep-equal": "^3.1.3",
68+
"miniprogram-api-typings": "^3.12.2",
6969
"rfdc": "^1.3.1"
7070
},
7171
"husky": {

test/index.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { BehaviorWithComputed } from '../src'
33
import { behavior as computedBehavior, computed, watch } from '../src'
44
import { defineComponent, renderComponent } from './env'
55

6+
declare const Behavior: adapter.BehaviorConstructor
7+
68
const innerHTML = (component: adapter.component.GeneralComponent) => {
79
return (component._$.$$ as unknown as HTMLElement).innerHTML
810
}

test/setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ const setup = () => {
5555
}
5656
}
5757

58+
//@ts-ignore
5859
module.exports = setup

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"declaration": true,
1414
"declarationDir": "./types",
1515
"emitDeclarationOnly": true,
16-
"skipLibCheck": true
16+
"skipLibCheck": true,
17+
"typeRoots": [ "./node_modules/@types", "./node_modules/miniprogram-api-typings" ]
1718
},
1819
"include": ["./src/**/*.ts"]
1920
}

types/behavior.d.ts

+67-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
export declare const behavior: string
1+
import type * as adapter from 'glass-easel-miniprogram-adapter';
2+
export declare const behavior: string;
3+
export declare function computed<TComputedDefinition1 extends {
4+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData, TProperty>) => any;
5+
}, TPrevData extends adapter.glassEasel.typeUtils.DataList, TProperty extends adapter.glassEasel.typeUtils.PropertyList>(ctx: adapter.builder.BuilderContext<TPrevData, TProperty, any>, computedDefinition1: TComputedDefinition1): adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
6+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
7+
}, TProperty>;
8+
export declare function computed<TComputedDefinition1 extends {
9+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData, TProperty>) => any;
10+
}, TComputedDefinition2 extends {
11+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
12+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
13+
}, TProperty>) => any;
14+
}, TPrevData extends adapter.glassEasel.typeUtils.DataList, TProperty extends adapter.glassEasel.typeUtils.PropertyList>(ctx: adapter.builder.BuilderContext<TPrevData, TProperty, any>, computedDefinition1: TComputedDefinition1, computedDefinition2: TComputedDefinition2): adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
15+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
16+
} & {
17+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
18+
}, TProperty>;
19+
export declare function computed<TComputedDefinition1 extends {
20+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData, TProperty>) => any;
21+
}, TComputedDefinition2 extends {
22+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
23+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
24+
}, TProperty>) => any;
25+
}, TComputedDefinition3 extends {
26+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
27+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
28+
} & {
29+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
30+
}, TProperty>) => any;
31+
}, TPrevData extends adapter.glassEasel.typeUtils.DataList, TProperty extends adapter.glassEasel.typeUtils.PropertyList>(ctx: adapter.builder.BuilderContext<TPrevData, TProperty, any>, computedDefinition1: TComputedDefinition1, computedDefinition2: TComputedDefinition2, computedDefinition3: TComputedDefinition3): adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
32+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
33+
} & {
34+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
35+
} & {
36+
[k in keyof TComputedDefinition3]: ReturnType<TComputedDefinition3[k]>;
37+
}, TProperty>;
38+
export declare function computed<TComputedDefinition1 extends {
39+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData, TProperty>) => any;
40+
}, TComputedDefinition2 extends {
41+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
42+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
43+
}, TProperty>) => any;
44+
}, TComputedDefinition3 extends {
45+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
46+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
47+
} & {
48+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
49+
}, TProperty>) => any;
50+
}, TComputedDefinition4 extends {
51+
[k: string]: (data: adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
52+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
53+
} & {
54+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
55+
} & {
56+
[k in keyof TComputedDefinition3]: ReturnType<TComputedDefinition3[k]>;
57+
}, TProperty>) => any;
58+
}, TPrevData extends adapter.glassEasel.typeUtils.DataList, TProperty extends adapter.glassEasel.typeUtils.PropertyList>(ctx: adapter.builder.BuilderContext<TPrevData, TProperty, any>, computedDefinition1: TComputedDefinition1, computedDefinition2: TComputedDefinition2, computedDefinition3: TComputedDefinition3, computedDefinition4: TComputedDefinition4): adapter.glassEasel.typeUtils.DataWithPropertyValues<TPrevData & {
59+
[k in keyof TComputedDefinition1]: ReturnType<TComputedDefinition1[k]>;
60+
} & {
61+
[k in keyof TComputedDefinition2]: ReturnType<TComputedDefinition2[k]>;
62+
} & {
63+
[k in keyof TComputedDefinition3]: ReturnType<TComputedDefinition3[k]>;
64+
} & {
65+
[k in keyof TComputedDefinition4]: ReturnType<TComputedDefinition4[k]>;
66+
}, TProperty>;
67+
export declare const watch: (ctx: adapter.builder.BuilderContext<any, any, any>, watchPath: string, listener: (...args: any[]) => void) => void;

types/data-path.d.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
export declare const parseMultiDataPaths: (path: string) => {
2-
path: string[]
3-
options: {
4-
deepCmp: boolean
5-
}
6-
}[]
7-
export declare const getDataOnPath: (data: unknown, path: Array<string>) => unknown
1+
export type DataPathWithOptions = {
2+
path: string[];
3+
options: {
4+
deepCmp: boolean;
5+
};
6+
};
7+
export declare const parseMultiDataPaths: (path: string) => DataPathWithOptions[];
8+
export declare const getDataOnPath: (data: unknown, path: Array<string>) => unknown;

types/data-tracer.d.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
interface IWrappedData {
2-
__rawObject__: unknown
3-
}
4-
export interface IRelatedPathValue {
5-
path: Array<string>
6-
value: unknown
7-
}
8-
export declare function create(data: unknown, relatedPathValues: Array<IRelatedPathValue>): any
9-
export declare function unwrap(wrapped: IWrappedData): any
10-
export {}
1+
export type RelatedPathValue = {
2+
kind: 'value';
3+
path: Array<string>;
4+
value: unknown;
5+
} | {
6+
kind: 'keys';
7+
path: Array<string>;
8+
keys: Array<string>;
9+
};
10+
export declare function create(data: unknown, relatedPathValues: Array<RelatedPathValue>): any;
11+
export declare function unwrap(wrapped: unknown): any;

types/index.d.ts

+22-75
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,24 @@
1-
/// <reference types="wechat-miniprogram" />
2-
/// <reference types="wechat-miniprogram" />
3-
/// <reference types="wechat-miniprogram" />
4-
export { behavior } from './behavior'
5-
type ComputedInstance<
6-
D extends WechatMiniprogram.Component.DataOption,
7-
P extends WechatMiniprogram.Component.PropertyOption,
8-
M extends WechatMiniprogram.Component.MethodOption,
9-
C extends Record<
10-
string,
11-
(
12-
data: D & {
13-
[K in keyof P]: any
14-
},
15-
) => any
16-
>,
17-
TCustomProperty extends WechatMiniprogram.IAnyObject = Record<string, never>,
18-
> = WechatMiniprogram.Component.Instance<D, P, M, TCustomProperty> & {
19-
data: {
20-
[K in keyof C]: ReturnType<C[K]>
21-
} & {
22-
[K in keyof P]: any
23-
}
24-
}
25-
type ComputedOptions<
26-
TData extends WechatMiniprogram.Component.DataOption,
27-
TProperty extends WechatMiniprogram.Component.PropertyOption,
28-
TMethod extends WechatMiniprogram.Component.MethodOption,
29-
TWatch extends Record<string, (...args: any[]) => void>,
30-
TComputed extends Record<
31-
string,
32-
(data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any
33-
>,
34-
TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {},
35-
> = (Partial<WechatMiniprogram.Component.Data<TData>> &
36-
Partial<WechatMiniprogram.Component.Property<TProperty>> &
37-
Partial<WechatMiniprogram.Component.Method<TMethod>> &
38-
Partial<WechatMiniprogram.Component.OtherOption> &
39-
Partial<WechatMiniprogram.Component.Lifetimes> & {
40-
watch?: TWatch
41-
computed?: TComputed
42-
template?: string
43-
}) &
44-
ThisType<ComputedInstance<TData, TProperty, TMethod, TComputed, TCustomInstanceProperty>>
45-
export declare function ComponentWithComputed<
46-
TData extends WechatMiniprogram.Component.DataOption,
47-
TProperty extends WechatMiniprogram.Component.PropertyOption,
48-
TMethod extends WechatMiniprogram.Component.MethodOption,
49-
TWatch extends Record<string, (...args: any[]) => void>,
50-
TComputed extends Record<
51-
string,
52-
(data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any
53-
>,
54-
TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {},
55-
>(
56-
options: ComputedOptions<TData, TProperty, TMethod, TWatch, TComputed, TCustomInstanceProperty>,
57-
): string
58-
export declare function BehaviorWithComputed<
59-
TData extends WechatMiniprogram.Behavior.DataOption,
60-
TProperty extends WechatMiniprogram.Behavior.PropertyOption,
61-
TMethod extends WechatMiniprogram.Behavior.MethodOption,
62-
TWatch extends Record<string, (...args: any[]) => void>,
63-
TComputed extends Record<
64-
string,
65-
(data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any
66-
>,
67-
TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {},
68-
>(
69-
options: ComputedOptions<TData, TProperty, TMethod, TWatch, TComputed, TCustomInstanceProperty>,
70-
): string
1+
export { behavior, computed, watch } from './behavior';
2+
type ComputedInstance<D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, C extends Record<string, (data: D & {
3+
[K in keyof P]: any;
4+
}) => any>, TCustomProperty extends WechatMiniprogram.IAnyObject = Record<string, never>> = WechatMiniprogram.Component.Instance<D, P, M, TCustomProperty> & {
5+
data: {
6+
[K in keyof C]: ReturnType<C[K]>;
7+
} & {
8+
[K in keyof P]: any;
9+
};
10+
};
11+
type ComputedOptions<TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption, TWatch extends Record<string, (...args: any[]) => void>, TComputed extends Record<string, (data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any>, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}> = (Partial<WechatMiniprogram.Component.Data<TData>> & Partial<WechatMiniprogram.Component.Property<TProperty>> & Partial<WechatMiniprogram.Component.Method<TMethod>> & Partial<WechatMiniprogram.Component.OtherOption> & Partial<WechatMiniprogram.Component.Lifetimes> & {
12+
watch?: TWatch;
13+
computed?: TComputed;
14+
template?: string;
15+
}) & ThisType<ComputedInstance<TData, TProperty, TMethod, TComputed, TCustomInstanceProperty>>;
16+
export declare function ComponentWithComputed<TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption, TWatch extends Record<string, (...args: any[]) => void>, TComputed extends Record<string, (data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any>, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}>(options: ComputedOptions<TData, TProperty, TMethod, TWatch, TComputed, TCustomInstanceProperty>): string;
17+
export declare function BehaviorWithComputed<TData extends WechatMiniprogram.Behavior.DataOption, TProperty extends WechatMiniprogram.Behavior.PropertyOption, TMethod extends WechatMiniprogram.Behavior.MethodOption, TWatch extends Record<string, (...args: any[]) => void>, TComputed extends Record<string, (data: TData & WechatMiniprogram.Component.PropertyOptionToData<TProperty>) => any>, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}>(options: ComputedOptions<TData, TProperty, TMethod, TWatch, TComputed, TCustomInstanceProperty>): string;
7118
export declare enum DataTracerMode {
72-
Auto = 0,
73-
Proxy = 1,
74-
DefineProperty = 2,
19+
Auto = 0,
20+
Proxy = 1,
21+
DefineProperty = 2
7522
}
76-
export declare const getCurrentDataTracerMode: () => DataTracerMode
77-
export declare const setCurrentDataTracerMode: (mode: DataTracerMode) => void
23+
export declare const getCurrentDataTracerMode: () => DataTracerMode;
24+
export declare const setCurrentDataTracerMode: (mode: DataTracerMode) => void;

0 commit comments

Comments
 (0)