56 | type Property = Component.Property
57 | type Method = Component.Method
58 |
59 | type DefinitionFilter = Component.DefinitionFilter
60 | type Lifetimes = Component.Lifetimes
61 |
62 | type OtherOption = Omit
63 | }
64 | }
65 | /** 注册一个 `behavior`,接受一个 `Object` 类型的参数。*/
66 | declare let Behavior: WechatMiniprogram.Behavior.Constructor
67 |
--------------------------------------------------------------------------------
/src/typings/wx/lib.wx.cloud.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2020 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | /////////////////////
24 | ///// WX Cloud Apis
25 | /////////////////////
26 |
27 | /**
28 | * Common interfaces and types
29 | */
30 |
31 | interface IAPIError {
32 | errMsg: string
33 | }
34 |
35 | interface IAPIParam {
36 | config?: ICloudConfig
37 | success?: (res: T) => void
38 | fail?: (err: IAPIError) => void
39 | complete?: (val: T | IAPIError) => void
40 | }
41 |
42 | interface IAPISuccessParam {
43 | errMsg: string
44 | }
45 |
46 | type IAPICompleteParam = IAPISuccessParam | IAPIError
47 |
48 | type IAPIFunction> = (param?: P) => Promise
49 |
50 | interface IInitCloudConfig {
51 | env?:
52 | | string
53 | | {
54 | database?: string
55 | functions?: string
56 | storage?: string
57 | }
58 | traceUser?: boolean
59 | }
60 |
61 | interface ICloudConfig {
62 | env?: string
63 | traceUser?: boolean
64 | }
65 |
66 | interface IICloudAPI {
67 | init: (config?: IInitCloudConfig) => void
68 | [api: string]: AnyFunction | IAPIFunction
69 | }
70 |
71 | interface ICloudService {
72 | name: string
73 |
74 | getAPIs: () => { [name: string]: IAPIFunction }
75 | }
76 |
77 | interface ICloudServices {
78 | [serviceName: string]: ICloudService
79 | }
80 |
81 | interface ICloudMetaData {
82 | session_id: string
83 | }
84 |
85 | declare class InternalSymbol {}
86 |
87 | interface AnyObject {
88 | [x: string]: any
89 | }
90 |
91 | type AnyArray = any[]
92 |
93 | type AnyFunction = (...args: any[]) => any
94 |
95 | /**
96 | * extend wx with cloud
97 | */
98 | interface WxCloud {
99 | init: (config?: ICloudConfig) => void
100 |
101 | callFunction(param: OQ): void
102 | callFunction(
103 | param: RQ
104 | ): Promise
105 |
106 | uploadFile(param: OQ): WechatMiniprogram.UploadTask
107 | uploadFile(
108 | param: RQ
109 | ): Promise
110 |
111 | downloadFile(
112 | param: OQ
113 | ): WechatMiniprogram.DownloadTask
114 | downloadFile(
115 | param: RQ
116 | ): Promise
117 |
118 | getTempFileURL(param: OQ): void
119 | getTempFileURL(
120 | param: RQ
121 | ): Promise
122 |
123 | deleteFile(param: OQ): void
124 | deleteFile(
125 | param: RQ
126 | ): Promise
127 |
128 | database: (config?: ICloudConfig) => DB.Database
129 | }
130 |
131 | declare namespace ICloud {
132 | interface ICloudAPIParam extends IAPIParam {
133 | config?: ICloudConfig
134 | }
135 |
136 | // === API: callFunction ===
137 | type CallFunctionData = AnyObject
138 |
139 | interface CallFunctionResult extends IAPISuccessParam {
140 | result: AnyObject | string | undefined
141 | }
142 |
143 | interface CallFunctionParam extends ICloudAPIParam {
144 | name: string
145 | data?: CallFunctionData
146 | slow?: boolean
147 | }
148 | // === end ===
149 |
150 | // === API: uploadFile ===
151 | interface UploadFileResult extends IAPISuccessParam {
152 | fileID: string
153 | statusCode: number
154 | }
155 |
156 | interface UploadFileParam extends ICloudAPIParam {
157 | cloudPath: string
158 | filePath: string
159 | header?: AnyObject
160 | }
161 | // === end ===
162 |
163 | // === API: downloadFile ===
164 | interface DownloadFileResult extends IAPISuccessParam {
165 | tempFilePath: string
166 | statusCode: number
167 | }
168 |
169 | interface DownloadFileParam extends ICloudAPIParam {
170 | fileID: string
171 | cloudPath?: string
172 | }
173 | // === end ===
174 |
175 | // === API: getTempFileURL ===
176 | interface GetTempFileURLResult extends IAPISuccessParam {
177 | fileList: GetTempFileURLResultItem[]
178 | }
179 |
180 | interface GetTempFileURLResultItem {
181 | fileID: string
182 | tempFileURL: string
183 | maxAge: number
184 | status: number
185 | errMsg: string
186 | }
187 |
188 | interface GetTempFileURLParam extends ICloudAPIParam {
189 | fileList: string[]
190 | }
191 | // === end ===
192 |
193 | // === API: deleteFile ===
194 | interface DeleteFileResult extends IAPISuccessParam {
195 | fileList: DeleteFileResultItem[]
196 | }
197 |
198 | interface DeleteFileResultItem {
199 | fileID: string
200 | status: number
201 | errMsg: string
202 | }
203 |
204 | interface DeleteFileParam extends ICloudAPIParam {
205 | fileList: string[]
206 | }
207 | // === end ===
208 | }
209 |
210 | // === Database ===
211 | declare namespace DB {
212 | /**
213 | * The class of all exposed cloud database instances
214 | */
215 | class Database {
216 | readonly config: ICloudConfig
217 | readonly command: DatabaseCommand
218 | readonly Geo: IGeo
219 | readonly serverDate: () => ServerDate
220 | readonly RegExp: IRegExpConstructor
221 |
222 | private constructor()
223 |
224 | collection(collectionName: string): CollectionReference
225 | }
226 |
227 | class CollectionReference extends Query {
228 | readonly collectionName: string
229 |
230 | private constructor(name: string, database: Database)
231 |
232 | doc(docId: string | number): DocumentReference
233 |
234 | add(options: OQ): void
235 | add(options: RQ): Promise
236 | }
237 |
238 | class DocumentReference {
239 | private constructor(docId: string | number, database: Database)
240 |
241 | field(object: object): this
242 |
243 | get(options: OQ): void
244 | get(options?: RQ): Promise
245 |
246 | set(options: OQ): void
247 | set(options?: RQ): Promise
248 |
249 | update(options: OQ): void
250 | update(
251 | options?: RQ
252 | ): Promise
253 |
254 | remove(options: OQ): void
255 | remove(
256 | options?: RQ
257 | ): Promise
258 |
259 | watch(options: IWatchOptions): RealtimeListener
260 | }
261 |
262 | class RealtimeListener {
263 | // "And Now His Watch Is Ended"
264 | close: () => Promise
265 | }
266 |
267 | class Query {
268 | where(condition: IQueryCondition): Query
269 |
270 | orderBy(fieldPath: string, order: string): Query
271 |
272 | limit(max: number): Query
273 |
274 | skip(offset: number): Query
275 |
276 | field(object: object): Query
277 |
278 | get(options: OQ): void
279 | get(options?: RQ): Promise
280 |
281 | count(options: OQ): void
282 | count(options?: RQ): Promise
283 |
284 | watch(options: IWatchOptions): RealtimeListener
285 | }
286 |
287 | interface DatabaseCommand {
288 | eq(val: any): DatabaseQueryCommand
289 | neq(val: any): DatabaseQueryCommand
290 | gt(val: any): DatabaseQueryCommand
291 | gte(val: any): DatabaseQueryCommand
292 | lt(val: any): DatabaseQueryCommand
293 | lte(val: any): DatabaseQueryCommand
294 | in(val: any[]): DatabaseQueryCommand
295 | nin(val: any[]): DatabaseQueryCommand
296 |
297 | geoNear(options: IGeoNearCommandOptions): DatabaseQueryCommand
298 | geoWithin(options: IGeoWithinCommandOptions): DatabaseQueryCommand
299 | geoIntersects(
300 | options: IGeoIntersectsCommandOptions
301 | ): DatabaseQueryCommand
302 |
303 | and(
304 | ...expressions: Array
305 | ): DatabaseLogicCommand
306 | or(
307 | ...expressions: Array
308 | ): DatabaseLogicCommand
309 | nor(
310 | ...expressions: Array
311 | ): DatabaseLogicCommand
312 | not(expression: DatabaseLogicCommand): DatabaseLogicCommand
313 |
314 | exists(val: boolean): DatabaseQueryCommand
315 |
316 | mod(divisor: number, remainder: number): DatabaseQueryCommand
317 |
318 | all(val: any[]): DatabaseQueryCommand
319 | elemMatch(val: any): DatabaseQueryCommand
320 | size(val: number): DatabaseQueryCommand
321 |
322 | set(val: any): DatabaseUpdateCommand
323 | remove(): DatabaseUpdateCommand
324 | inc(val: number): DatabaseUpdateCommand
325 | mul(val: number): DatabaseUpdateCommand
326 | min(val: number): DatabaseUpdateCommand
327 | max(val: number): DatabaseUpdateCommand
328 | rename(val: string): DatabaseUpdateCommand
329 | bit(val: number): DatabaseUpdateCommand
330 |
331 | push(...values: any[]): DatabaseUpdateCommand
332 | pop(): DatabaseUpdateCommand
333 | shift(): DatabaseUpdateCommand
334 | unshift(...values: any[]): DatabaseUpdateCommand
335 | addToSet(val: any): DatabaseUpdateCommand
336 | pull(val: any): DatabaseUpdateCommand
337 | pullAll(val: any): DatabaseUpdateCommand
338 |
339 | project: {
340 | slice(val: number | [number, number]): DatabaseProjectionCommand
341 | }
342 |
343 | aggregate: {
344 | __safe_props__?: Set
345 |
346 | abs(val: any): DatabaseAggregateCommand
347 | add(val: any): DatabaseAggregateCommand
348 | addToSet(val: any): DatabaseAggregateCommand
349 | allElementsTrue(val: any): DatabaseAggregateCommand
350 | and(val: any): DatabaseAggregateCommand
351 | anyElementTrue(val: any): DatabaseAggregateCommand
352 | arrayElemAt(val: any): DatabaseAggregateCommand
353 | arrayToObject(val: any): DatabaseAggregateCommand
354 | avg(val: any): DatabaseAggregateCommand
355 | ceil(val: any): DatabaseAggregateCommand
356 | cmp(val: any): DatabaseAggregateCommand
357 | concat(val: any): DatabaseAggregateCommand
358 | concatArrays(val: any): DatabaseAggregateCommand
359 | cond(val: any): DatabaseAggregateCommand
360 | convert(val: any): DatabaseAggregateCommand
361 | dateFromParts(val: any): DatabaseAggregateCommand
362 | dateToParts(val: any): DatabaseAggregateCommand
363 | dateFromString(val: any): DatabaseAggregateCommand
364 | dateToString(val: any): DatabaseAggregateCommand
365 | dayOfMonth(val: any): DatabaseAggregateCommand
366 | dayOfWeek(val: any): DatabaseAggregateCommand
367 | dayOfYear(val: any): DatabaseAggregateCommand
368 | divide(val: any): DatabaseAggregateCommand
369 | eq(val: any): DatabaseAggregateCommand
370 | exp(val: any): DatabaseAggregateCommand
371 | filter(val: any): DatabaseAggregateCommand
372 | first(val: any): DatabaseAggregateCommand
373 | floor(val: any): DatabaseAggregateCommand
374 | gt(val: any): DatabaseAggregateCommand
375 | gte(val: any): DatabaseAggregateCommand
376 | hour(val: any): DatabaseAggregateCommand
377 | ifNull(val: any): DatabaseAggregateCommand
378 | in(val: any): DatabaseAggregateCommand
379 | indexOfArray(val: any): DatabaseAggregateCommand
380 | indexOfBytes(val: any): DatabaseAggregateCommand
381 | indexOfCP(val: any): DatabaseAggregateCommand
382 | isArray(val: any): DatabaseAggregateCommand
383 | isoDayOfWeek(val: any): DatabaseAggregateCommand
384 | isoWeek(val: any): DatabaseAggregateCommand
385 | isoWeekYear(val: any): DatabaseAggregateCommand
386 | last(val: any): DatabaseAggregateCommand
387 | let(val: any): DatabaseAggregateCommand
388 | literal(val: any): DatabaseAggregateCommand
389 | ln(val: any): DatabaseAggregateCommand
390 | log(val: any): DatabaseAggregateCommand
391 | log10(val: any): DatabaseAggregateCommand
392 | lt(val: any): DatabaseAggregateCommand
393 | lte(val: any): DatabaseAggregateCommand
394 | ltrim(val: any): DatabaseAggregateCommand
395 | map(val: any): DatabaseAggregateCommand
396 | max(val: any): DatabaseAggregateCommand
397 | mergeObjects(val: any): DatabaseAggregateCommand
398 | meta(val: any): DatabaseAggregateCommand
399 | min(val: any): DatabaseAggregateCommand
400 | millisecond(val: any): DatabaseAggregateCommand
401 | minute(val: any): DatabaseAggregateCommand
402 | mod(val: any): DatabaseAggregateCommand
403 | month(val: any): DatabaseAggregateCommand
404 | multiply(val: any): DatabaseAggregateCommand
405 | neq(val: any): DatabaseAggregateCommand
406 | not(val: any): DatabaseAggregateCommand
407 | objectToArray(val: any): DatabaseAggregateCommand
408 | or(val: any): DatabaseAggregateCommand
409 | pow(val: any): DatabaseAggregateCommand
410 | push(val: any): DatabaseAggregateCommand
411 | range(val: any): DatabaseAggregateCommand
412 | reduce(val: any): DatabaseAggregateCommand
413 | reverseArray(val: any): DatabaseAggregateCommand
414 | rtrim(val: any): DatabaseAggregateCommand
415 | second(val: any): DatabaseAggregateCommand
416 | setDifference(val: any): DatabaseAggregateCommand
417 | setEquals(val: any): DatabaseAggregateCommand
418 | setIntersection(val: any): DatabaseAggregateCommand
419 | setIsSubset(val: any): DatabaseAggregateCommand
420 | setUnion(val: any): DatabaseAggregateCommand
421 | size(val: any): DatabaseAggregateCommand
422 | slice(val: any): DatabaseAggregateCommand
423 | split(val: any): DatabaseAggregateCommand
424 | sqrt(val: any): DatabaseAggregateCommand
425 | stdDevPop(val: any): DatabaseAggregateCommand
426 | stdDevSamp(val: any): DatabaseAggregateCommand
427 | strcasecmp(val: any): DatabaseAggregateCommand
428 | strLenBytes(val: any): DatabaseAggregateCommand
429 | strLenCP(val: any): DatabaseAggregateCommand
430 | substr(val: any): DatabaseAggregateCommand
431 | substrBytes(val: any): DatabaseAggregateCommand
432 | substrCP(val: any): DatabaseAggregateCommand
433 | subtract(val: any): DatabaseAggregateCommand
434 | sum(val: any): DatabaseAggregateCommand
435 | switch(val: any): DatabaseAggregateCommand
436 | toBool(val: any): DatabaseAggregateCommand
437 | toDate(val: any): DatabaseAggregateCommand
438 | toDecimal(val: any): DatabaseAggregateCommand
439 | toDouble(val: any): DatabaseAggregateCommand
440 | toInt(val: any): DatabaseAggregateCommand
441 | toLong(val: any): DatabaseAggregateCommand
442 | toObjectId(val: any): DatabaseAggregateCommand
443 | toString(val: any): DatabaseAggregateCommand
444 | toLower(val: any): DatabaseAggregateCommand
445 | toUpper(val: any): DatabaseAggregateCommand
446 | trim(val: any): DatabaseAggregateCommand
447 | trunc(val: any): DatabaseAggregateCommand
448 | type(val: any): DatabaseAggregateCommand
449 | week(val: any): DatabaseAggregateCommand
450 | year(val: any): DatabaseAggregateCommand
451 | zip(val: any): DatabaseAggregateCommand
452 | }
453 | }
454 |
455 | class DatabaseAggregateCommand {}
456 |
457 | enum LOGIC_COMMANDS_LITERAL {
458 | AND = 'and',
459 | OR = 'or',
460 | NOT = 'not',
461 | NOR = 'nor',
462 | }
463 |
464 | class DatabaseLogicCommand {
465 | and(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
466 | or(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
467 | nor(...expressions: DatabaseLogicCommand[]): DatabaseLogicCommand
468 | not(expression: DatabaseLogicCommand): DatabaseLogicCommand
469 | }
470 |
471 | enum QUERY_COMMANDS_LITERAL {
472 | // comparison
473 | EQ = 'eq',
474 | NEQ = 'neq',
475 | GT = 'gt',
476 | GTE = 'gte',
477 | LT = 'lt',
478 | LTE = 'lte',
479 | IN = 'in',
480 | NIN = 'nin',
481 | // geo
482 | GEO_NEAR = 'geoNear',
483 | GEO_WITHIN = 'geoWithin',
484 | GEO_INTERSECTS = 'geoIntersects',
485 | // element
486 | EXISTS = 'exists',
487 | // evaluation
488 | MOD = 'mod',
489 | // array
490 | ALL = 'all',
491 | ELEM_MATCH = 'elemMatch',
492 | SIZE = 'size',
493 | }
494 |
495 | class DatabaseQueryCommand extends DatabaseLogicCommand {
496 | eq(val: any): DatabaseLogicCommand
497 | neq(val: any): DatabaseLogicCommand
498 | gt(val: any): DatabaseLogicCommand
499 | gte(val: any): DatabaseLogicCommand
500 | lt(val: any): DatabaseLogicCommand
501 | lte(val: any): DatabaseLogicCommand
502 | in(val: any[]): DatabaseLogicCommand
503 | nin(val: any[]): DatabaseLogicCommand
504 |
505 | exists(val: boolean): DatabaseLogicCommand
506 |
507 | mod(divisor: number, remainder: number): DatabaseLogicCommand
508 |
509 | all(val: any[]): DatabaseLogicCommand
510 | elemMatch(val: any): DatabaseLogicCommand
511 | size(val: number): DatabaseLogicCommand
512 |
513 | geoNear(options: IGeoNearCommandOptions): DatabaseLogicCommand
514 | geoWithin(options: IGeoWithinCommandOptions): DatabaseLogicCommand
515 | geoIntersects(
516 | options: IGeoIntersectsCommandOptions
517 | ): DatabaseLogicCommand
518 | }
519 |
520 | enum PROJECTION_COMMANDS_LITERAL {
521 | SLICE = 'slice',
522 | }
523 |
524 | class DatabaseProjectionCommand {}
525 |
526 | enum UPDATE_COMMANDS_LITERAL {
527 | // field
528 | SET = 'set',
529 | REMOVE = 'remove',
530 | INC = 'inc',
531 | MUL = 'mul',
532 | MIN = 'min',
533 | MAX = 'max',
534 | RENAME = 'rename',
535 | // bitwise
536 | BIT = 'bit',
537 | // array
538 | PUSH = 'push',
539 | POP = 'pop',
540 | SHIFT = 'shift',
541 | UNSHIFT = 'unshift',
542 | ADD_TO_SET = 'addToSet',
543 | PULL = 'pull',
544 | PULL_ALL = 'pullAll',
545 | }
546 |
547 | class DatabaseUpdateCommand {}
548 |
549 | class Batch {}
550 |
551 | /**
552 | * A contract that all API provider must adhere to
553 | */
554 | class APIBaseContract<
555 | PROMISE_RETURN,
556 | CALLBACK_RETURN,
557 | PARAM extends IAPIParam,
558 | CONTEXT = any
559 | > {
560 | getContext(param: PARAM): CONTEXT
561 |
562 | /**
563 | * In case of callback-style invocation, this function will be called
564 | */
565 | getCallbackReturn(param: PARAM, context: CONTEXT): CALLBACK_RETURN
566 |
567 | getFinalParam(param: PARAM, context: CONTEXT): T
568 |
569 | run(param: T): Promise
570 | }
571 |
572 | interface IGeoPointConstructor {
573 | new (longitude: number, latitide: number): GeoPoint
574 | new (geojson: IGeoJSONPoint): GeoPoint
575 | (longitude: number, latitide: number): GeoPoint
576 | (geojson: IGeoJSONPoint): GeoPoint
577 | }
578 |
579 | interface IGeoMultiPointConstructor {
580 | new (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
581 | (points: GeoPoint[] | IGeoJSONMultiPoint): GeoMultiPoint
582 | }
583 |
584 | interface IGeoLineStringConstructor {
585 | new (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
586 | (points: GeoPoint[] | IGeoJSONLineString): GeoLineString
587 | }
588 |
589 | interface IGeoMultiLineStringConstructor {
590 | new (
591 | lineStrings: GeoLineString[] | IGeoJSONMultiLineString
592 | ): GeoMultiLineString
593 | (
594 | lineStrings: GeoLineString[] | IGeoJSONMultiLineString
595 | ): GeoMultiLineString
596 | }
597 |
598 | interface IGeoPolygonConstructor {
599 | new (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
600 | (lineStrings: GeoLineString[] | IGeoJSONPolygon): GeoPolygon
601 | }
602 |
603 | interface IGeoMultiPolygonConstructor {
604 | new (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
605 | (polygons: GeoPolygon[] | IGeoJSONMultiPolygon): GeoMultiPolygon
606 | }
607 |
608 | interface IGeo {
609 | Point: IGeoPointConstructor
610 | MultiPoint: IGeoMultiPointConstructor
611 | LineString: IGeoLineStringConstructor
612 | MultiLineString: IGeoMultiLineStringConstructor
613 | Polygon: IGeoPolygonConstructor
614 | MultiPolygon: IGeoMultiPolygonConstructor
615 | }
616 |
617 | interface IGeoJSONPoint {
618 | type: 'Point'
619 | coordinates: [number, number]
620 | }
621 |
622 | interface IGeoJSONMultiPoint {
623 | type: 'MultiPoint'
624 | coordinates: Array<[number, number]>
625 | }
626 |
627 | interface IGeoJSONLineString {
628 | type: 'LineString'
629 | coordinates: Array<[number, number]>
630 | }
631 |
632 | interface IGeoJSONMultiLineString {
633 | type: 'MultiLineString'
634 | coordinates: Array>
635 | }
636 |
637 | interface IGeoJSONPolygon {
638 | type: 'Polygon'
639 | coordinates: Array>
640 | }
641 |
642 | interface IGeoJSONMultiPolygon {
643 | type: 'MultiPolygon'
644 | coordinates: Array>>
645 | }
646 |
647 | type IGeoJSONObject =
648 | | IGeoJSONPoint
649 | | IGeoJSONMultiPoint
650 | | IGeoJSONLineString
651 | | IGeoJSONMultiLineString
652 | | IGeoJSONPolygon
653 | | IGeoJSONMultiPolygon
654 |
655 | abstract class GeoPoint {
656 | longitude: number
657 | latitude: number
658 |
659 | constructor(longitude: number, latitude: number)
660 |
661 | toJSON(): object
662 | toString(): string
663 | }
664 |
665 | abstract class GeoMultiPoint {
666 | points: GeoPoint[]
667 |
668 | constructor(points: GeoPoint[])
669 |
670 | toJSON(): IGeoJSONMultiPoint
671 | toString(): string
672 | }
673 |
674 | abstract class GeoLineString {
675 | points: GeoPoint[]
676 |
677 | constructor(points: GeoPoint[])
678 |
679 | toJSON(): IGeoJSONLineString
680 | toString(): string
681 | }
682 |
683 | abstract class GeoMultiLineString {
684 | lines: GeoLineString[]
685 |
686 | constructor(lines: GeoLineString[])
687 |
688 | toJSON(): IGeoJSONMultiLineString
689 | toString(): string
690 | }
691 |
692 | abstract class GeoPolygon {
693 | lines: GeoLineString[]
694 |
695 | constructor(lines: GeoLineString[])
696 |
697 | toJSON(): IGeoJSONPolygon
698 | toString(): string
699 | }
700 |
701 | abstract class GeoMultiPolygon {
702 | polygons: GeoPolygon[]
703 |
704 | constructor(polygons: GeoPolygon[])
705 |
706 | toJSON(): IGeoJSONMultiPolygon
707 | toString(): string
708 | }
709 |
710 | type GeoInstance =
711 | | GeoPoint
712 | | GeoMultiPoint
713 | | GeoLineString
714 | | GeoMultiLineString
715 | | GeoPolygon
716 | | GeoMultiPolygon
717 |
718 | interface IGeoNearCommandOptions {
719 | geometry: GeoPoint
720 | maxDistance?: number
721 | minDistance?: number
722 | }
723 |
724 | interface IGeoWithinCommandOptions {
725 | geometry: GeoPolygon | GeoMultiPolygon
726 | }
727 |
728 | interface IGeoIntersectsCommandOptions {
729 | geometry:
730 | | GeoPoint
731 | | GeoMultiPoint
732 | | GeoLineString
733 | | GeoMultiLineString
734 | | GeoPolygon
735 | | GeoMultiPolygon
736 | }
737 |
738 | interface IServerDateOptions {
739 | offset: number
740 | }
741 |
742 | abstract class ServerDate {
743 | readonly options: IServerDateOptions
744 | constructor(options?: IServerDateOptions)
745 | }
746 |
747 | interface IRegExpOptions {
748 | regexp: string
749 | options?: string
750 | }
751 |
752 | interface IRegExpConstructor {
753 | new (options: IRegExpOptions): RegExp
754 | (options: IRegExpOptions): RegExp
755 | }
756 |
757 | abstract class RegExp {
758 | readonly regexp: string
759 | readonly options: string
760 | constructor(options: IRegExpOptions)
761 | }
762 |
763 | type DocumentId = string | number
764 |
765 | interface IDocumentData {
766 | _id?: DocumentId
767 | [key: string]: any
768 | }
769 |
770 | type IDBAPIParam = IAPIParam
771 |
772 | interface IAddDocumentOptions extends IDBAPIParam {
773 | data: IDocumentData
774 | }
775 |
776 | type IGetDocumentOptions = IDBAPIParam
777 |
778 | type ICountDocumentOptions = IDBAPIParam
779 |
780 | interface IUpdateDocumentOptions extends IDBAPIParam {
781 | data: IUpdateCondition
782 | }
783 |
784 | interface IUpdateSingleDocumentOptions extends IDBAPIParam {
785 | data: IUpdateCondition
786 | }
787 |
788 | interface ISetDocumentOptions extends IDBAPIParam {
789 | data: IUpdateCondition
790 | }
791 |
792 | interface ISetSingleDocumentOptions extends IDBAPIParam {
793 | data: IUpdateCondition
794 | }
795 |
796 | interface IRemoveDocumentOptions extends IDBAPIParam {
797 | query: IQueryCondition
798 | }
799 |
800 | type IRemoveSingleDocumentOptions = IDBAPIParam
801 |
802 | interface IWatchOptions {
803 | // server realtime data init & change event
804 | onChange: (snapshot: ISnapshot) => void
805 | // error while connecting / listening
806 | onError: (error: any) => void
807 | }
808 |
809 | interface ISnapshot {
810 | id: number
811 | docChanges: ISingleDBEvent[]
812 | docs: Record
813 | type?: SnapshotType
814 | }
815 |
816 | type SnapshotType = 'init'
817 |
818 | interface ISingleDBEvent {
819 | id: number
820 | dataType: DataType
821 | queueType: QueueType
822 | docId: string
823 | doc: Record
824 | updatedFields?: Record
825 | removedFields?: string[]
826 | }
827 |
828 | type DataType = 'init' | 'update' | 'replace' | 'add' | 'remove' | 'limit'
829 |
830 | type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
831 |
832 | interface IQueryCondition {
833 | [key: string]: any
834 | }
835 |
836 | type IStringQueryCondition = string
837 |
838 | interface IQueryResult extends IAPISuccessParam {
839 | data: IDocumentData[]
840 | }
841 |
842 | interface IQuerySingleResult extends IAPISuccessParam {
843 | data: IDocumentData
844 | }
845 |
846 | interface IUpdateCondition {
847 | [key: string]: any
848 | }
849 |
850 | type IStringUpdateCondition = string
851 |
852 | interface IAddResult extends IAPISuccessParam {
853 | _id: DocumentId
854 | }
855 |
856 | interface IUpdateResult extends IAPISuccessParam {
857 | stats: {
858 | updated: number
859 | // created: number,
860 | }
861 | }
862 |
863 | interface ISetResult extends IAPISuccessParam {
864 | _id: DocumentId
865 | stats: {
866 | updated: number
867 | created: number
868 | }
869 | }
870 |
871 | interface IRemoveResult extends IAPISuccessParam {
872 | stats: {
873 | removed: number
874 | }
875 | }
876 |
877 | interface ICountResult extends IAPISuccessParam {
878 | total: number
879 | }
880 | }
881 |
882 | type Optional = { [K in keyof T]+?: T[K] }
883 |
884 | type OQ<
885 | T extends Optional<
886 | Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
887 | >
888 | > =
889 | | (RQ & Required>)
890 | | (RQ & Required>)
891 | | (RQ & Required>)
892 | | (RQ & Required>)
893 | | (RQ & Required>)
894 | | (RQ & Required>)
895 | | (RQ & Required>)
896 |
897 | type RQ<
898 | T extends Optional<
899 | Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
900 | >
901 | > = Pick>
902 |
--------------------------------------------------------------------------------
/src/typings/wx/lib.wx.component.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2020 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | declare namespace WechatMiniprogram {
24 | namespace Component {
25 | type Instance<
26 | TData extends DataOption,
27 | TProperty extends PropertyOption,
28 | TMethod extends Partial
29 | > = InstanceProperties &
30 | InstanceMethods &
31 | TMethod & {
32 | /** 组件数据,**包括内部数据和属性值** */
33 | data: TData & PropertyOptionToData
34 | /** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
35 | properties: TData & PropertyOptionToData
36 | }
37 | type TrivialInstance = Instance
38 | type TrivialOption = Options
39 | type Options<
40 | TData extends DataOption,
41 | TProperty extends PropertyOption,
42 | TMethod extends MethodOption
43 | > = Partial> &
44 | Partial> &
45 | Partial> &
46 | Partial &
47 | Partial &
48 | ThisType>
49 | interface Constructor {
50 | <
51 | TData extends DataOption,
52 | TProperty extends PropertyOption,
53 | TMethod extends MethodOption
54 | >(
55 | options: Options
56 | ): string
57 | }
58 | type DataOption = Record
59 | type PropertyOption = Record
60 | type MethodOption = Record any>
61 |
62 | interface Data {
63 | /** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
64 | data?: D
65 | }
66 | interface Property {
67 | /** 组件的对外属性,是属性名到属性设置的映射表 */
68 | properties: P
69 | }
70 | interface Method {
71 | /** 组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html) */
72 | methods: M
73 | }
74 | type PropertyType =
75 | | StringConstructor
76 | | NumberConstructor
77 | | BooleanConstructor
78 | | ArrayConstructor
79 | | ObjectConstructor
80 | | null
81 | type ValueType = T extends StringConstructor
82 | ? string
83 | : T extends NumberConstructor
84 | ? number
85 | : T extends BooleanConstructor
86 | ? boolean
87 | : T extends ArrayConstructor
88 | ? any[]
89 | : T extends ObjectConstructor
90 | ? IAnyObject
91 | : any
92 | type FullProperty = {
93 | /** 属性类型 */
94 | type: T
95 | /** 属性初始值 */
96 | value?: ValueType
97 | /** 属性值被更改时的响应函数 */
98 | observer?:
99 | | string
100 | | ((
101 | newVal: ValueType,
102 | oldVal: ValueType,
103 | changedPath: Array
104 | ) => void)
105 | /** 属性的类型(可以指定多个) */
106 | optionalTypes?: ShortProperty[]
107 | }
108 | type AllFullProperty =
109 | | FullProperty
110 | | FullProperty
111 | | FullProperty
112 | | FullProperty
113 | | FullProperty
114 | | FullProperty
115 | type ShortProperty =
116 | | StringConstructor
117 | | NumberConstructor
118 | | BooleanConstructor
119 | | ArrayConstructor
120 | | ObjectConstructor
121 | | null
122 | type AllProperty = AllFullProperty | ShortProperty
123 | type PropertyToData = T extends ShortProperty
124 | ? ValueType
125 | : FullPropertyToData>
126 | type FullPropertyToData = ValueType<
127 | T['type']
128 | >
129 | type PropertyOptionToData = {
130 | [name in keyof P]: PropertyToData
131 | }
132 |
133 | interface InstanceProperties {
134 | /** 组件的文件路径 */
135 | is: string
136 | /** 节点id */
137 | id: string
138 | /** 节点dataset */
139 | dataset: Record
140 | }
141 |
142 | interface InstanceMethods {
143 | /** `setData` 函数用于将数据从逻辑层发送到视图层
144 | *(异步),同时改变对应的 `this.data` 的值(同步)。
145 | *
146 | * **注意:**
147 | *
148 | * 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
149 | * 1. 仅支持设置可 JSON 化的数据。
150 | * 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
151 | * 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
152 | */
153 | setData(
154 | /** 这次要改变的数据
155 | *
156 | * 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
157 | *
158 | * 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
159 | */
160 | data: Partial & IAnyObject,
161 | /** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
162 | callback?: () => void
163 | ): void
164 |
165 | /** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
166 | hasBehavior(behavior: object): void
167 | /** 触发事件,参见组件事件 */
168 | triggerEvent(
169 | name: string,
170 | detail?: object,
171 | options?: TriggerEventOption
172 | ): void
173 | /** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
174 | createSelectorQuery(): SelectorQuery
175 | /** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
176 | createIntersectionObserver(
177 | options: CreateIntersectionObserverOption
178 | ): IntersectionObserver
179 | /** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
180 | selectComponent(selector: string): TrivialInstance
181 | /** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
182 | selectAllComponents(selector: string): TrivialInstance[]
183 | /**
184 | * 选取当前组件节点所在的组件实例(即组件的引用者),返回它的组件实例对象(会被 `wx://component-export` 影响)
185 | *
186 | * 最低基础库版本:[`2.8.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
187 | **/
188 | selectOwnerComponent(): TrivialInstance
189 | /** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
190 | getRelationNodes(relationKey: string): TrivialInstance[]
191 | /**
192 | * 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)
193 | *
194 | * 最低基础库版本:[`2.4.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
195 | **/
196 | groupSetData(callback?: () => void): void
197 | /**
198 | * 返回当前页面的 custom-tab-bar 的组件实例
199 | *
200 | * 最低基础库版本:[`2.6.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
201 | **/
202 | getTabBar(): TrivialInstance
203 | /**
204 | * 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内
205 | *
206 | * 最低基础库版本:[`2.7.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
207 | **/
208 | getPageId(): string
209 | /**
210 | * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
211 | *
212 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
213 | **/
214 | animate(
215 | selector: string,
216 | keyFrames: KeyFrame[],
217 | duration: number,
218 | callback: () => void
219 | ): void
220 | /**
221 | * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
222 | *
223 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
224 | **/
225 | animate(
226 | selector: string,
227 | keyFrames: ScrollTimelineKeyframe[],
228 | duration: number,
229 | scrollTimeline: ScrollTimelineOption
230 | ): void
231 | /**
232 | * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
233 | *
234 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
235 | **/
236 | clearAnimation(selector: string, callback: () => void): void
237 | /**
238 | * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
239 | *
240 | * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
241 | **/
242 | clearAnimation(
243 | selector: string,
244 | options: ClearAnimationOptions,
245 | callback: () => void
246 | ): void
247 | getOpenerEventChannel(): EventChannel
248 | }
249 |
250 | interface ComponentOptions {
251 | /**
252 | * [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot)
253 | */
254 | multipleSlots?: boolean
255 | /**
256 | * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
257 | */
258 | addGlobalClass?: boolean
259 | /**
260 | * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
261 | */
262 | styleIsolation?:
263 | | 'isolated'
264 | | 'apply-shared'
265 | | 'shared'
266 | | 'page-isolated'
267 | | 'page-apply-shared'
268 | | 'page-shared'
269 | /**
270 | * [纯数据字段](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/pure-data.html) 是一些不用于界面渲染的 data 字段,可以用于提升页面更新性能。从小程序基础库版本 2.8.2 开始支持。
271 | */
272 | pureDataPattern?: RegExp
273 | }
274 |
275 | interface TriggerEventOption {
276 | /** 事件是否冒泡
277 | *
278 | * 默认值: `false`
279 | */
280 | bubbles?: boolean
281 | /** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
282 | *
283 | * 默认值: `false`
284 | */
285 | composed?: boolean
286 | /** 事件是否拥有捕获阶段
287 | *
288 | * 默认值: `false`
289 | */
290 | capturePhase?: boolean
291 | }
292 |
293 | interface RelationOption {
294 | /** 目标组件的相对关系 */
295 | type: 'parent' | 'child' | 'ancestor' | 'descendant'
296 | /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
297 | linked?(target: TrivialInstance): void
298 | /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
299 | linkChanged?(target: TrivialInstance): void
300 | /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
301 | unlinked?(target: TrivialInstance): void
302 | /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
303 | target?: string
304 | }
305 |
306 | interface PageLifetimes {
307 | /** 页面生命周期回调—监听页面显示
308 | *
309 | * 页面显示/切入前台时触发。
310 | */
311 | show(): void
312 | /** 页面生命周期回调—监听页面隐藏
313 | *
314 | * 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
315 | */
316 | hide(): void
317 | /** 页面生命周期回调—监听页面尺寸变化
318 | *
319 | * 所在页面尺寸变化时执行
320 | */
321 | resize(size: Page.IResizeOption): void
322 | }
323 |
324 | type DefinitionFilter = (
325 | /** 使用该 behavior 的 component/behavior 的定义对象 */
326 | defFields: T,
327 | /** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */
328 | definitionFilterArr?: DefinitionFilter[]
329 | ) => void
330 |
331 | interface Lifetimes {
332 | /** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
333 | *
334 | * 最低基础库: `2.2.3` */
335 | lifetimes: Partial<{
336 | /**
337 | * 在组件实例刚刚被创建时执行,注意此时不能调用 `setData`
338 | *
339 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
340 | */
341 | created(): void
342 | /**
343 | * 在组件实例进入页面节点树时执行
344 | *
345 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
346 | */
347 | attached(): void
348 | /**
349 | * 在组件在视图层布局完成后执行
350 | *
351 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
352 | */
353 | ready(): void
354 | /**
355 | * 在组件实例被移动到节点树另一个位置时执行
356 | *
357 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
358 | */
359 | moved(): void
360 | /**
361 | * 在组件实例被从页面节点树移除时执行
362 | *
363 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
364 | */
365 | detached(): void
366 | /**
367 | * 每当组件方法抛出错误时执行
368 | *
369 | * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
370 | */
371 | error(err: Error): void
372 | }>
373 | /**
374 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
375 | *
376 | * 在组件实例刚刚被创建时执行
377 | *
378 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
379 | */
380 | created(): void
381 | /**
382 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
383 | *
384 | * 在组件实例进入页面节点树时执行
385 | *
386 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
387 | */
388 | attached(): void
389 | /**
390 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
391 | *
392 | * 在组件在视图层布局完成后执行
393 | *
394 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
395 | */
396 | ready(): void
397 | /**
398 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
399 | *
400 | * 在组件实例被移动到节点树另一个位置时执行
401 | *
402 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
403 | */
404 | moved(): void
405 | /**
406 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
407 | *
408 | * 在组件实例被从页面节点树移除时执行
409 | *
410 | * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
411 | */
412 | detached(): void
413 | /**
414 | * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
415 | *
416 | * 每当组件方法抛出错误时执行
417 | *
418 | * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
419 | */
420 | error(err: Error): void
421 | }
422 |
423 | interface OtherOption {
424 | /** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) */
425 | behaviors: string[]
426 | /**
427 | * 组件数据字段监听器,用于监听 properties 和 data 的变化,参见 [数据监听器](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/observer.html)
428 | *
429 | * 最低基础库版本:[`2.6.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
430 | */
431 | observers: Record any>
432 | /** 组件间关系定义,参见 [组件间关系](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html) */
433 | relations: {
434 | [componentName: string]: RelationOption
435 | }
436 | /** 组件接受的外部样式类,参见 [外部样式类](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) */
437 | externalClasses?: string[]
438 | /** 组件所在页面的生命周期声明对象,参见 [组件生命周期](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html)
439 | *
440 | * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
441 | pageLifetimes?: Partial
442 | /** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
443 | options: ComponentOptions
444 |
445 | /** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html)
446 | *
447 | * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
448 | definitionFilter?: DefinitionFilter
449 | }
450 |
451 | interface KeyFrame {
452 | /** 关键帧的偏移,范围[0-1] */
453 | offset?: number
454 | /** 动画缓动函数 */
455 | ease?: string
456 | /** 基点位置,即 CSS transform-origin */
457 | transformOrigin?: string
458 | /** 背景颜色,即 CSS background-color */
459 | backgroundColor?: string
460 | /** 底边位置,即 CSS bottom */
461 | bottom?: number | string
462 | /** 高度,即 CSS height */
463 | height?: number | string
464 | /** 左边位置,即 CSS left */
465 | left?: number | string
466 | /** 宽度,即 CSS width */
467 | width?: number | string
468 | /** 不透明度,即 CSS opacity */
469 | opacity?: number | string
470 | /** 右边位置,即 CSS right */
471 | right?: number | string
472 | /** 顶边位置,即 CSS top */
473 | top?: number | string
474 | /** 变换矩阵,即 CSS transform matrix */
475 | matrix?: number[]
476 | /** 三维变换矩阵,即 CSS transform matrix3d */
477 | matrix3d?: number[]
478 | /** 旋转,即 CSS transform rotate */
479 | rotate?: number
480 | /** 三维旋转,即 CSS transform rotate3d */
481 | rotate3d?: number[]
482 | /** X 方向旋转,即 CSS transform rotateX */
483 | rotateX?: number
484 | /** Y 方向旋转,即 CSS transform rotateY */
485 | rotateY?: number
486 | /** Z 方向旋转,即 CSS transform rotateZ */
487 | rotateZ?: number
488 | /** 缩放,即 CSS transform scale */
489 | scale?: number[]
490 | /** 三维缩放,即 CSS transform scale3d */
491 | scale3d?: number[]
492 | /** X 方向缩放,即 CSS transform scaleX */
493 | scaleX?: number
494 | /** Y 方向缩放,即 CSS transform scaleY */
495 | scaleY?: number
496 | /** Z 方向缩放,即 CSS transform scaleZ */
497 | scaleZ?: number
498 | /** 倾斜,即 CSS transform skew */
499 | skew?: number[]
500 | /** X 方向倾斜,即 CSS transform skewX */
501 | skewX?: number
502 | /** Y 方向倾斜,即 CSS transform skewY */
503 | skewY?: number
504 | /** 位移,即 CSS transform translate */
505 | translate?: Array
506 | /** 三维位移,即 CSS transform translate3d */
507 | translate3d?: Array
508 | /** X 方向位移,即 CSS transform translateX */
509 | translateX?: number | string
510 | /** Y 方向位移,即 CSS transform translateY */
511 | translateY?: number | string
512 | /** Z 方向位移,即 CSS transform translateZ */
513 | translateZ?: number | string
514 | }
515 | interface ClearAnimationOptions {
516 | /** 基点位置,即 CSS transform-origin */
517 | transformOrigin?: boolean
518 | /** 背景颜色,即 CSS background-color */
519 | backgroundColor?: boolean
520 | /** 底边位置,即 CSS bottom */
521 | bottom?: boolean
522 | /** 高度,即 CSS height */
523 | height?: boolean
524 | /** 左边位置,即 CSS left */
525 | left?: boolean
526 | /** 宽度,即 CSS width */
527 | width?: boolean
528 | /** 不透明度,即 CSS opacity */
529 | opacity?: boolean
530 | /** 右边位置,即 CSS right */
531 | right?: boolean
532 | /** 顶边位置,即 CSS top */
533 | top?: boolean
534 | /** 变换矩阵,即 CSS transform matrix */
535 | matrix?: boolean
536 | /** 三维变换矩阵,即 CSS transform matrix3d */
537 | matrix3d?: boolean
538 | /** 旋转,即 CSS transform rotate */
539 | rotate?: boolean
540 | /** 三维旋转,即 CSS transform rotate3d */
541 | rotate3d?: boolean
542 | /** X 方向旋转,即 CSS transform rotateX */
543 | rotateX?: boolean
544 | /** Y 方向旋转,即 CSS transform rotateY */
545 | rotateY?: boolean
546 | /** Z 方向旋转,即 CSS transform rotateZ */
547 | rotateZ?: boolean
548 | /** 缩放,即 CSS transform scale */
549 | scale?: boolean
550 | /** 三维缩放,即 CSS transform scale3d */
551 | scale3d?: boolean
552 | /** X 方向缩放,即 CSS transform scaleX */
553 | scaleX?: boolean
554 | /** Y 方向缩放,即 CSS transform scaleY */
555 | scaleY?: boolean
556 | /** Z 方向缩放,即 CSS transform scaleZ */
557 | scaleZ?: boolean
558 | /** 倾斜,即 CSS transform skew */
559 | skew?: boolean
560 | /** X 方向倾斜,即 CSS transform skewX */
561 | skewX?: boolean
562 | /** Y 方向倾斜,即 CSS transform skewY */
563 | skewY?: boolean
564 | /** 位移,即 CSS transform translate */
565 | translate?: boolean
566 | /** 三维位移,即 CSS transform translate3d */
567 | translate3d?: boolean
568 | /** X 方向位移,即 CSS transform translateX */
569 | translateX?: boolean
570 | /** Y 方向位移,即 CSS transform translateY */
571 | translateY?: boolean
572 | /** Z 方向位移,即 CSS transform translateZ */
573 | translateZ?: boolean
574 | }
575 | interface ScrollTimelineKeyframe {
576 | composite?: 'replace' | 'add' | 'accumulate' | 'auto'
577 | easing?: string
578 | offset?: number | null
579 | [property: string]: string | number | null | undefined
580 | }
581 | interface ScrollTimelineOption {
582 | /** 指定滚动元素的选择器(只支持 scroll-view),该元素滚动时会驱动动画的进度 */
583 | scrollSource: string
584 | /** 指定滚动的方向。有效值为 horizontal 或 vertical */
585 | orientation?: string
586 | /** 指定开始驱动动画进度的滚动偏移量,单位 px */
587 | startScrollOffset: number
588 | /** 指定停止驱动动画进度的滚动偏移量,单位 px */
589 | endScrollOffset: number
590 | /** 起始和结束的滚动范围映射的时间长度,该时间可用于与关键帧动画里的时间 (duration) 相匹配,单位 ms */
591 | timeRange: number
592 | }
593 | }
594 | }
595 | /** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
596 | *
597 | * * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
598 | * * 生命周期函数无法在组件方法中通过 `this` 访问到。
599 | * * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
600 | * * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
601 | * * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
602 | * * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
603 | */
604 | declare let Component: WechatMiniprogram.Component.Constructor
605 |
--------------------------------------------------------------------------------
/src/typings/wx/lib.wx.event.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2020 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | declare namespace WechatMiniprogram {
24 | interface Touch {
25 | clientX: number
26 | clientY: number
27 | force: number
28 | identifier: number
29 | pageX: number
30 | pageY: number
31 | }
32 | interface Event {
33 | currentTarget: {
34 | id: string
35 | dataset: {
36 | [key: string]: string
37 | }
38 | offsetTop: number
39 | offsetLeft: number
40 | }
41 | target: {
42 | id: string
43 | dataset: {
44 | [key: string]: string
45 | }
46 | offsetTop: number
47 | offsetLeft: number
48 | }
49 | timeStamp: number
50 | touches: Touch[]
51 | mut: boolean
52 | type: string
53 | }
54 | interface TapEvent extends Event {
55 | changedTouches: []
56 | detail: {
57 | x: number
58 | y: number
59 | }
60 | type: 'tap'
61 | }
62 |
63 | interface InputEvent extends Event {
64 | changedTouches: []
65 | detail: {
66 | cursor: number
67 | keyCode: number
68 | value: string
69 | }
70 | type: 'input'
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/typings/wx/lib.wx.page.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) 2020 Tencent, Inc. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | ***************************************************************************** */
22 |
23 | declare namespace WechatMiniprogram {
24 | namespace Page {
25 | type Instance<
26 | TData extends DataOption,
27 | TCustom extends CustomOption
28 | > = OptionalInterface &
29 | InstanceProperties &
30 | InstanceMethods &
31 | Data &
32 | TCustom
33 | type Options<
34 | TData extends DataOption,
35 | TCustom extends CustomOption
36 | > = (TCustom & Partial> & Partial) &
37 | ThisType>
38 | type TrivialInstance = Instance
39 | interface Constructor {
40 | (
41 | options: Options
42 | ): void
43 | }
44 | interface ILifetime {
45 | /** 生命周期回调—监听页面加载
46 | *
47 | * 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。
48 | */
49 | onLoad(
50 | /** 打开当前页面路径中的参数 */
51 | query: Record
52 | ): void
53 | /** 生命周期回调—监听页面显示
54 | *
55 | * 页面显示/切入前台时触发。
56 | */
57 | onShow(): void
58 | /** 生命周期回调—监听页面初次渲染完成
59 | *
60 | * 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
61 | *
62 |
63 | * 注意:对界面内容进行设置的 API 如`wx.setNavigationBarTitle`,请在`onReady`之后进行。
64 | */
65 | onReady(): void
66 | /** 生命周期回调—监听页面隐藏
67 | *
68 | * 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
69 | */
70 | onHide(): void
71 | /** 生命周期回调—监听页面卸载
72 | *
73 | * 页面卸载时触发。如`redirectTo`或`navigateBack`到其他页面时。
74 | */
75 | onUnload(): void
76 | /** 监听用户下拉动作
77 | *
78 | * 监听用户下拉刷新事件。
79 | * - 需要在`app.json`的`window`选项中或页面配置中开启`enablePullDownRefresh`。
80 | * - 可以通过`wx.startPullDownRefresh`触发下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
81 | * - 当处理完数据刷新后,`wx.stopPullDownRefresh`可以停止当前页面的下拉刷新。
82 | */
83 | onPullDownRefresh(): void
84 | /** 页面上拉触底事件的处理函数
85 | *
86 | * 监听用户上拉触底事件。
87 | * - 可以在`app.json`的`window`选项中或页面配置中设置触发距离`onReachBottomDistance`。
88 | * - 在触发距离内滑动期间,本事件只会被触发一次。
89 | */
90 | onReachBottom(): void
91 | /** 用户点击右上角转发
92 | *
93 | * 监听用户点击页面内转发按钮(`