├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .husky └── pre-commit ├── .prettierrc ├── CHANGELOG.md ├── CONTRIBUTION.md ├── LICENSE ├── README.md ├── jest.config.js ├── lerna.json ├── package.json ├── packages ├── aliauto │ ├── README.md │ ├── package.json │ └── types │ │ └── index.d.ts ├── alipay │ ├── package.json │ └── types │ │ └── index.d.ts ├── global │ ├── package.json │ └── types │ │ ├── index.d.ts │ │ ├── lib.app.d.ts │ │ ├── lib.component.d.ts │ │ ├── lib.global.d.ts │ │ ├── lib.mixin.d.ts │ │ ├── lib.page.d.ts │ │ ├── lib.shared.d.ts │ │ ├── lib.sjs.d.ts │ │ └── lib.worker.d.ts └── my │ ├── package.json │ └── types │ ├── index.d.ts │ ├── lib.my.d.ts │ └── lib.my.extra.d.ts ├── scripts └── set-release-tag.sh ├── tests ├── global │ ├── app.test.ts │ ├── component.test.ts │ ├── mixin.test.ts │ ├── mixins.test.ts │ ├── other.test.ts │ ├── page.test.ts │ ├── this.test.ts │ └── worker.test.ts ├── my │ ├── cloud.test.ts │ └── index.test.ts └── tsconfig.json └── widget ├── alipay ├── package.json └── types │ └── index.d.ts └── my ├── package.json └── types ├── index.d.ts ├── lib.my.d.ts └── lib.my.extra.d.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Use Node.js 14.x 11 | uses: actions/setup-node@v1 12 | with: 13 | node-version: 14.x 14 | - name: Run CI 15 | run: | 16 | npm run init 17 | npm run ci 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # due to network reason, github actions cannot use npmmirror 2 | yarn.lock 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | lerna-debug.log* 11 | .pnpm-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed 20 | *.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | *.lcov 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | node_modules/ 46 | jspm_packages/ 47 | 48 | # Snowpack dependency directory (https://snowpack.dev/) 49 | web_modules/ 50 | 51 | # TypeScript cache 52 | *.tsbuildinfo 53 | 54 | # Optional npm cache directory 55 | .npm 56 | 57 | # Optional eslint cache 58 | .eslintcache 59 | 60 | # Optional stylelint cache 61 | .stylelintcache 62 | 63 | # Microbundle cache 64 | .rpt2_cache/ 65 | .rts2_cache_cjs/ 66 | .rts2_cache_es/ 67 | .rts2_cache_umd/ 68 | 69 | # Optional REPL history 70 | .node_repl_history 71 | 72 | # Output of 'npm pack' 73 | *.tgz 74 | 75 | # Yarn Integrity file 76 | .yarn-integrity 77 | 78 | # dotenv environment variable files 79 | .env 80 | .env.development.local 81 | .env.test.local 82 | .env.production.local 83 | .env.local 84 | 85 | # parcel-bundler cache (https://parceljs.org/) 86 | .cache 87 | .parcel-cache 88 | 89 | # Next.js build output 90 | .next 91 | out 92 | 93 | # Nuxt.js build / generate output 94 | .nuxt 95 | dist 96 | 97 | # Gatsby files 98 | .cache/ 99 | # Comment in the public line in if your project uses Gatsby and not Next.js 100 | # https://nextjs.org/blog/next-9-1#public-directory-support 101 | # public 102 | 103 | # vuepress build output 104 | .vuepress/dist 105 | 106 | # vuepress v2.x temp and cache directory 107 | .temp 108 | .cache 109 | 110 | # Docusaurus cache and generated files 111 | .docusaurus 112 | 113 | # Serverless directories 114 | .serverless/ 115 | 116 | # FuseBox cache 117 | .fusebox/ 118 | 119 | # DynamoDB Local files 120 | .dynamodb/ 121 | 122 | # TernJS port file 123 | .tern-port 124 | 125 | # Stores VSCode versions used for testing VSCode extensions 126 | .vscode-test 127 | 128 | # yarn v2 129 | .yarn/cache 130 | .yarn/unplugged 131 | .yarn/build-state.yml 132 | .yarn/install-state.gz 133 | .pnp.* 134 | 135 | # General 136 | .DS_Store 137 | .AppleDouble 138 | .LSOverride 139 | 140 | # Icon must end with two \r 141 | Icon 142 | 143 | 144 | # Thumbnails 145 | ._* 146 | 147 | # Files that might appear in the root of a volume 148 | .DocumentRevisions-V100 149 | .fseventsd 150 | .Spotlight-V100 151 | .TemporaryItems 152 | .Trashes 153 | .VolumeIcon.icns 154 | .com.apple.timemachine.donotpresent 155 | 156 | # Directories potentially created on remote AFP share 157 | .AppleDB 158 | .AppleDesktop 159 | Network Trash Folder 160 | Temporary Items 161 | .apdisk 162 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [](https://github.com/ant-mini-program/api-typings/compare/v3.0.14...v) (2024-01-16) 2 | 3 | 4 | 5 | ## [3.0.14](https://github.com/ant-mini-program/api-typings/compare/v3.0.13...v3.0.14) (2024-01-16) 6 | 7 | 8 | ### Features 9 | 10 | * **worker:** inherit from lib.webworker.d.ts ([#42](https://github.com/ant-mini-program/api-typings/issues/42)) ([ca45bb3](https://github.com/ant-mini-program/api-typings/commit/ca45bb36aa0aeb7ed9cea30238b36a78da6504fd)) 11 | 12 | 13 | 14 | ## [3.0.13](https://github.com/ant-mini-program/api-typings/compare/v3.0.12...v3.0.13) (2024-01-15) 15 | 16 | 17 | ### Features 18 | 19 | * add lib.worker.d.ts ([#41](https://github.com/ant-mini-program/api-typings/issues/41)) ([5f642ef](https://github.com/ant-mini-program/api-typings/commit/5f642ef1bbecd4ffc07c383e6b8188751034d5e0)) 20 | 21 | 22 | 23 | ## [3.0.12](https://github.com/ant-mini-program/api-typings/compare/v3.0.11...v3.0.12) (2023-10-18) 24 | 25 | 26 | ### Features 27 | 28 | * support wechat ([#39](https://github.com/ant-mini-program/api-typings/issues/39)) ([4729f29](https://github.com/ant-mini-program/api-typings/commit/4729f290d5f1898f315ca59bd3479f873d278af2)) 29 | * update typings ([cedef8b](https://github.com/ant-mini-program/api-typings/commit/cedef8be799b8bd01e1d55c9ea74029db9463b1b)) 30 | 31 | 32 | 33 | ## [3.0.11](https://github.com/ant-mini-program/api-typings/compare/v3.0.10...v3.0.11) (2023-09-14) 34 | 35 | 36 | ### Features 37 | 38 | * init widget packages ([fba5b62](https://github.com/ant-mini-program/api-typings/commit/fba5b62b3328b05cf7ae661206ecd61f8bcf7f32)) 39 | 40 | 41 | 42 | ## [3.0.10](https://github.com/ant-mini-program/api-typings/compare/v3.0.9...v3.0.10) (2023-09-12) 43 | 44 | 45 | ### Features 46 | 47 | * update typings ([6759566](https://github.com/ant-mini-program/api-typings/commit/6759566d63d62f04d8694607f022f72825c789a9)) 48 | 49 | 50 | 51 | ## [3.0.9](https://github.com/ant-mini-program/api-typings/compare/v3.0.8...v3.0.9) (2023-08-14) 52 | 53 | 54 | ### Features 55 | 56 | * connectSocket support multiple param ([e47bbce](https://github.com/ant-mini-program/api-typings/commit/e47bbcef15f69cd7b33a71cd1a9c1ab1b925084d)) 57 | * update typings ([3935d1d](https://github.com/ant-mini-program/api-typings/commit/3935d1ddb11e5795e729d87410f2095c7d807974)) 58 | 59 | 60 | 61 | ## [3.0.8](https://github.com/ant-mini-program/api-typings/compare/v3.0.6...v3.0.8) (2023-06-15) 62 | 63 | 64 | ### Bug Fixes 65 | 66 | * remove invalid typings ([1ab50ac](https://github.com/ant-mini-program/api-typings/commit/1ab50ac8eba1b62fc693c510a9a644edc21aa134)) 67 | 68 | 69 | ### Features 70 | 71 | * add require ([54a07ec](https://github.com/ant-mini-program/api-typings/commit/54a07ecbf4da963e9231a4fb19201fa94e55dc3a)) 72 | * add requirePlugin.async ([9c5ed67](https://github.com/ant-mini-program/api-typings/commit/9c5ed672a74ff00b8cf170e7f273fd2987897feb)) 73 | * update typings ([c4435b0](https://github.com/ant-mini-program/api-typings/commit/c4435b0caac2f09465c9685d8edb49839b57d9da)) 74 | * update typings ([c59706f](https://github.com/ant-mini-program/api-typings/commit/c59706f074e8fc4621b3929529419daa293c4198)) 75 | * update typings ([1c0403d](https://github.com/ant-mini-program/api-typings/commit/1c0403dae68eafe1f207c2d7cf7a3ad99094896c)) 76 | 77 | 78 | 79 | ## [3.0.6](https://github.com/ant-mini-program/api-typings/compare/v3.0.5...v3.0.6) (2023-03-13) 80 | 81 | 82 | ### Features 83 | 84 | * update typings ([75fcb0b](https://github.com/ant-mini-program/api-typings/commit/75fcb0bc648e9c77661e33293b53ff2dcae55b44)) 85 | 86 | 87 | 88 | ## [3.0.5](https://github.com/ant-mini-program/api-typings/compare/v3.0.3...v3.0.5) (2023-02-21) 89 | 90 | 91 | ### Features 92 | 93 | * add mixin typing ([2997add](https://github.com/ant-mini-program/api-typings/commit/2997add00aae8c692721ed88813551d90798d95c)) 94 | * Component构造器允许识别额外参数,并作为对应实例的属性 ([#34](https://github.com/ant-mini-program/api-typings/issues/34)) ([1f6822e](https://github.com/ant-mini-program/api-typings/commit/1f6822ee10ce5d07800ca449f0dff093cc1274e6)) 95 | 96 | 97 | 98 | ## [3.0.3](https://github.com/ant-mini-program/api-typings/compare/v3.0.1...v3.0.3) (2023-02-07) 99 | 100 | 101 | ### Bug Fixes 102 | 103 | * add missing return value of fs sync method ([1dd91a5](https://github.com/ant-mini-program/api-typings/commit/1dd91a5ff039cd9c17aaac63dfc5c3ec4d522e10)), closes [#32](https://github.com/ant-mini-program/api-typings/issues/32) 104 | * unload params ([e0babf4](https://github.com/ant-mini-program/api-typings/commit/e0babf4bd2c11799b366d7672c8934635323a65a)) 105 | 106 | 107 | ### Features 108 | 109 | * **component:** add virtualHost options ([#31](https://github.com/ant-mini-program/api-typings/issues/31)) ([facd0ff](https://github.com/ant-mini-program/api-typings/commit/facd0ff18b48fe33acb1f6b982ba5eebff04b642)) 110 | 111 | 112 | 113 | ## [3.0.1](https://github.com/ant-mini-program/api-typings/compare/v3.0.0...v3.0.1) (2023-02-01) 114 | 115 | 116 | ### Features 117 | 118 | * update typings ([2c2a114](https://github.com/ant-mini-program/api-typings/commit/2c2a1143710de2d547722c2194a35314cdd38036)) 119 | 120 | 121 | 122 | # [3.0.0](https://github.com/ant-mini-program/api-typings/compare/v2.0.19...v3.0.0) (2023-01-06) 123 | 124 | 125 | ### Bug Fixes 126 | 127 | * return type ([#24](https://github.com/ant-mini-program/api-typings/issues/24)) ([8742a3f](https://github.com/ant-mini-program/api-typings/commit/8742a3faccf4324c9a05e1850e07a0ff5a68d3d2)) 128 | 129 | 130 | ### Features 131 | 132 | * remove unused declarations ([578145f](https://github.com/ant-mini-program/api-typings/commit/578145f0046fbeb6c6a2601c62e504765c67a84b)) 133 | * update typings ([eeecac0](https://github.com/ant-mini-program/api-typings/commit/eeecac033e3b92c48fe48d86e51438ef2322ed7d)) 134 | * update typings ([59616dc](https://github.com/ant-mini-program/api-typings/commit/59616dc7a6933b3b480eaf9355f4cbd129ee9ebc)) 135 | * 基础库 2.8.5 Component新增功能 ([#18](https://github.com/ant-mini-program/api-typings/issues/18)) ([6eb99b5](https://github.com/ant-mini-program/api-typings/commit/6eb99b5e8eb506bb3de31a1cfb061b2cc96814b8)) 136 | * 新增 setUpdatePerformanceListener 类型 & lint hook ([#25](https://github.com/ant-mini-program/api-typings/issues/25)) ([584d77b](https://github.com/ant-mini-program/api-typings/commit/584d77bfae55468e0ef4d73462230ddaee0189f4)) 137 | 138 | 139 | 140 | ## [2.0.19](https://github.com/ant-mini-program/api-typings/compare/v2.0.18...v2.0.19) (2022-12-10) 141 | 142 | 143 | ### Features 144 | 145 | * add sjs typings ([#16](https://github.com/ant-mini-program/api-typings/issues/16)) ([4064c38](https://github.com/ant-mini-program/api-typings/commit/4064c384f3107f0064831ba62edd6fea5330d46a)) 146 | 147 | 148 | 149 | ## [2.0.18](https://github.com/ant-mini-program/api-typings/compare/v2.0.17...v2.0.18) (2022-12-06) 150 | 151 | 152 | 153 | ## [2.0.17](https://github.com/ant-mini-program/api-typings/compare/v2.0.16...v2.0.17) (2022-12-06) 154 | 155 | 156 | ### Bug Fixes 157 | 158 | * remove duplicates enums ([2a6c87c](https://github.com/ant-mini-program/api-typings/commit/2a6c87c1be9c36c102829e39d37d4fe6572c0afc)) 159 | 160 | 161 | ### Features 162 | 163 | * update typings ([e4ae34e](https://github.com/ant-mini-program/api-typings/commit/e4ae34e0b792cc8411a046da2f42814e5c9ad4a5)) 164 | * update typings ([8a4293a](https://github.com/ant-mini-program/api-typings/commit/8a4293ab70c793d432252bff14703d8bac976ada)) 165 | 166 | 167 | 168 | ## [2.0.16](https://github.com/ant-mini-program/api-typings/compare/v2.0.15...v2.0.16) (2022-11-28) 169 | 170 | 171 | ### Features 172 | 173 | * update typings ([7048386](https://github.com/ant-mini-program/api-typings/commit/7048386434c5b7831eb535c31a2715ebf2483564)) 174 | 175 | 176 | 177 | ## [2.0.15](https://github.com/ant-mini-program/api-typings/compare/v2.0.14...v2.0.15) (2022-11-14) 178 | 179 | 180 | ### Features 181 | 182 | * **page:** 新增 Mixin 属性 ([#14](https://github.com/ant-mini-program/api-typings/issues/14)) ([d210726](https://github.com/ant-mini-program/api-typings/commit/d2107267e57faadcb0c53af5fd21e3677b396f55)) 183 | 184 | 185 | 186 | ## [2.0.14](https://github.com/ant-mini-program/api-typings/compare/v2.0.13...v2.0.14) (2022-11-04) 187 | 188 | 189 | 190 | ## [2.0.13](https://github.com/ant-mini-program/api-typings/compare/v2.0.12...v2.0.13) (2022-11-04) 191 | 192 | 193 | ### Features 194 | 195 | * update typings ([602aa74](https://github.com/ant-mini-program/api-typings/commit/602aa7440e083af9f6508990590ebd734e4dbff6)) 196 | 197 | 198 | 199 | ## [2.0.12](https://github.com/ant-mini-program/api-typings/compare/v2.0.11...v2.0.12) (2022-11-02) 200 | 201 | 202 | ### Features 203 | 204 | * add more api ([56cc744](https://github.com/ant-mini-program/api-typings/commit/56cc744382ea80615dd5936d2eac2d200c5bed36)) 205 | * update comments ([7391f3c](https://github.com/ant-mini-program/api-typings/commit/7391f3c28502f1007f4ff5d81e421becc006a554)) 206 | 207 | 208 | 209 | ## [2.0.11](https://github.com/ant-mini-program/api-typings/compare/v2.0.10...v2.0.11) (2022-10-21) 210 | 211 | 212 | ### Features 213 | 214 | * improve comments ([1e015ea](https://github.com/ant-mini-program/api-typings/commit/1e015ea8f44fcc94ff4b3f2aaf1c286a38e06696)) 215 | 216 | 217 | 218 | ## [2.0.10](https://github.com/ant-mini-program/api-typings/compare/v2.0.9...v2.0.10) (2022-10-20) 219 | 220 | 221 | ### Features 222 | 223 | * update api ([b847101](https://github.com/ant-mini-program/api-typings/commit/b8471015e1f08d16d5e73730a1497c4595b86579)) 224 | 225 | 226 | 227 | ## [2.0.9](https://github.com/ant-mini-program/api-typings/compare/v2.0.8...v2.0.9) (2022-10-17) 228 | 229 | 230 | 231 | ## [2.0.8](https://github.com/ant-mini-program/api-typings/compare/v2.0.7...v2.0.8) (2022-10-12) 232 | 233 | 234 | ### Features 235 | 236 | * add observers ([#12](https://github.com/ant-mini-program/api-typings/issues/12)) ([42d3f1f](https://github.com/ant-mini-program/api-typings/commit/42d3f1f758b61481727f9a0fc17668935b4d10d6)) 237 | 238 | 239 | 240 | ## [2.0.7](https://github.com/ant-mini-program/api-typings/compare/v2.0.6...v2.0.7) (2022-09-28) 241 | 242 | 243 | ### Features 244 | 245 | * update api typings ([c95b6df](https://github.com/ant-mini-program/api-typings/commit/c95b6df3aeb460cebff2056f8bb21be32d8badb9)) 246 | 247 | 248 | 249 | ## [2.0.6](https://github.com/ant-mini-program/api-typings/compare/v2.0.5...v2.0.6) (2022-09-15) 250 | 251 | 252 | 253 | ## [2.0.5](https://github.com/ant-mini-program/api-typings/compare/v2.0.4...v2.0.5) (2022-09-15) 254 | 255 | 256 | ### Features 257 | 258 | * update types ([303902c](https://github.com/ant-mini-program/api-typings/commit/303902c9db2a4a0affeeeb5646218e138b91ed99)) 259 | 260 | 261 | 262 | ## [2.0.4](https://github.com/ant-mini-program/api-typings/compare/v2.0.3...v2.0.4) (2022-08-30) 263 | 264 | 265 | ### Bug Fixes 266 | 267 | * chooseDistrict related ([2c1e3de](https://github.com/ant-mini-program/api-typings/commit/2c1e3de9c11167ab4b3ed99022b0ef0ee0e267c9)) 268 | 269 | 270 | 271 | ## [2.0.3](https://github.com/ant-mini-program/api-typings/compare/v2.0.2...v2.0.3) (2022-08-25) 272 | 273 | 274 | ### Bug Fixes 275 | 276 | * return task not work as expect ([ea4b8bb](https://github.com/ant-mini-program/api-typings/commit/ea4b8bbf971d8722813d664ec1075d0214b5ca23)) 277 | 278 | 279 | ### Features 280 | 281 | * update types summary ([eec74fb](https://github.com/ant-mini-program/api-typings/commit/eec74fb4809e55b263a88e8463034ea8279cb6cc)) 282 | 283 | 284 | 285 | ## [2.0.2](https://github.com/ant-mini-program/api-typings/compare/v2.0.1...v2.0.2) (2022-08-12) 286 | 287 | 288 | ### Features 289 | 290 | * add aliauto types ([#2](https://github.com/ant-mini-program/api-typings/issues/2)) ([0ea7f74](https://github.com/ant-mini-program/api-typings/commit/0ea7f74deaaed8e0be3e8c11015eb9aad9732677)) 291 | * add page instance methods ([#11](https://github.com/ant-mini-program/api-typings/issues/11)) ([7d7b809](https://github.com/ant-mini-program/api-typings/commit/7d7b80947b2cc11886d44632d192bbdf23b79cc9)) 292 | 293 | 294 | 295 | ## [2.0.1](https://github.com/ant-mini-program/api-typings/compare/v2.0.0...v2.0.1) (2022-07-29) 296 | 297 | 298 | ### Features 299 | 300 | * update typings ([#7](https://github.com/ant-mini-program/api-typings/issues/7)) ([e1459a4](https://github.com/ant-mini-program/api-typings/commit/e1459a47be684546e6d25d4cde270ee88039dc9f)) 301 | 302 | 303 | 304 | # [2.0.0](https://github.com/ant-mini-program/api-typings/compare/v1.0.33...v2.0.0) (2022-06-22) 305 | 306 | 307 | ### Bug Fixes 308 | 309 | * remove the type made props fully optional ([a8da536](https://github.com/ant-mini-program/api-typings/commit/a8da536f0d69649b51ba201abfb3119ec2dd74b8)) 310 | 311 | 312 | 313 | ## [1.0.33](https://github.com/ant-mini-program/api-typings/compare/v1.0.32...v1.0.33) (2022-06-17) 314 | 315 | 316 | ### Features 317 | 318 | * update typings ([166a803](https://github.com/ant-mini-program/api-typings/commit/166a803a491e4ec176d6143814b8ad79cc7b3169)), closes [#3](https://github.com/ant-mini-program/api-typings/issues/3) 319 | 320 | 321 | 322 | ## [1.0.32](https://github.com/ant-mini-program/api-typings/compare/v1.0.31...v1.0.32) (2022-06-06) 323 | 324 | 325 | ### Bug Fixes 326 | 327 | * add some sfc func typing ([b073b7c](https://github.com/ant-mini-program/api-typings/commit/b073b7cc3ac05dbac0d5e781a3b7b93f206a47e5)) 328 | 329 | 330 | ### Features 331 | 332 | * add missing functions ([b66edf1](https://github.com/ant-mini-program/api-typings/commit/b66edf12b3e6b8ceca3ce6d6593da5c1dbb7be58)) 333 | 334 | 335 | 336 | ## [1.0.31](https://github.com/ant-mini-program/api-typings/compare/v1.0.30...v1.0.31) (2022-05-25) 337 | 338 | 339 | ### Features 340 | 341 | * update typings ([ba9c43d](https://github.com/ant-mini-program/api-typings/commit/ba9c43dc2ea7c68c37248334222f4da38df10a60)) 342 | 343 | 344 | 345 | ## [1.0.30](https://github.com/ant-mini-program/api-typings/compare/v1.0.29...v1.0.30) (2022-05-24) 346 | 347 | 348 | ### Features 349 | 350 | * update typings ([21ef5a3](https://github.com/ant-mini-program/api-typings/commit/21ef5a3cf7b36f2417242c54153beda429468da2)) 351 | 352 | 353 | 354 | ## [1.0.29](https://github.com/ant-mini-program/api-typings/compare/v1.0.28...v1.0.29) (2022-05-24) 355 | 356 | 357 | 358 | ## [1.0.28](https://github.com/ant-mini-program/api-typings/compare/v1.0.27...v1.0.28) (2022-05-24) 359 | 360 | 361 | 362 | ## [1.0.27](https://github.com/ant-mini-program/api-typings/compare/v1.0.26...v1.0.27) (2022-05-24) 363 | 364 | 365 | 366 | ## [1.0.26](https://github.com/ant-mini-program/api-typings/compare/v1.0.25...v1.0.26) (2022-05-24) 367 | 368 | 369 | ### Bug Fixes 370 | 371 | * getTabbar return undefined ([e5bb386](https://github.com/ant-mini-program/api-typings/commit/e5bb38647a918b0bb0a7bf65081894a391bc9305)) 372 | 373 | 374 | ### Features 375 | 376 | * add getTabBar API type ([#1](https://github.com/ant-mini-program/api-typings/issues/1)) ([3b5fc10](https://github.com/ant-mini-program/api-typings/commit/3b5fc105038faeadecb76fde5533d74f2ca4ceb2)) 377 | 378 | 379 | 380 | ## [1.0.25](https://github.com/ant-mini-program/api-typings/compare/v1.0.24...v1.0.25) (2022-05-20) 381 | 382 | 383 | 384 | ## [1.0.24](https://github.com/ant-mini-program/api-typings/compare/v1.0.23...v1.0.24) (2022-05-20) 385 | 386 | 387 | ### Bug Fixes 388 | 389 | * fix some typings ([a2063c3](https://github.com/ant-mini-program/api-typings/commit/a2063c3ea61fc2ba8ba8b3ff42e7976472960f25)) 390 | 391 | 392 | 393 | ## [1.0.23](https://github.com/ant-mini-program/api-typings/compare/v1.0.22...v1.0.23) (2022-05-18) 394 | 395 | 396 | ### Features 397 | 398 | * add requirePlugin ([84bdc05](https://github.com/ant-mini-program/api-typings/commit/84bdc05b75ce1d526e43463be4b342019019c78d)) 399 | 400 | 401 | 402 | ## [1.0.22](https://github.com/ant-mini-program/api-typings/compare/v1.0.21...v1.0.22) (2022-05-07) 403 | 404 | 405 | ### Features 406 | 407 | * update my.* typings ([2fbe264](https://github.com/ant-mini-program/api-typings/commit/2fbe26488d77556a8e1dfbe4f08bc9d8a4f1ce35)) 408 | 409 | 410 | 411 | ## [1.0.21](https://github.com/ant-mini-program/api-typings/compare/v1.0.20...v1.0.21) (2022-05-06) 412 | 413 | 414 | ### Features 415 | 416 | * make offXXX args optional ([6a825d7](https://github.com/ant-mini-program/api-typings/commit/6a825d776fd717c25e410d402370a36008d7b668)) 417 | 418 | 419 | 420 | ## [1.0.20](https://github.com/ant-mini-program/api-typings/compare/v1.0.19...v1.0.20) (2022-04-29) 421 | 422 | 423 | ### Features 424 | 425 | * add more api ([0c6f7b6](https://github.com/ant-mini-program/api-typings/commit/0c6f7b6ed7045e7c4270505988944270447d91fa)) 426 | 427 | 428 | 429 | ## [1.0.19](https://github.com/ant-mini-program/api-typings/compare/v1.0.18...v1.0.19) (2022-04-29) 430 | 431 | 432 | 433 | ## [1.0.18](https://github.com/ant-mini-program/api-typings/compare/v1.0.17...v1.0.18) (2022-04-29) 434 | 435 | 436 | ### Bug Fixes 437 | 438 | * use `/tests/**/*.test.ts'], 8 | }; 9 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*", "widget/*"], 3 | "version": "3.0.14" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mini-types", 3 | "private": true, 4 | "repository": { 5 | "type": "git", 6 | "url": "git@github.com:ant-mini-program/api-typings.git" 7 | }, 8 | "scripts": { 9 | "init": "yarn install && lerna bootstrap", 10 | "publish:prod": "lerna publish --exact --force-publish='*' --no-push", 11 | "publish:prod:patch": "lerna publish patch --exact --force-publish='*' --no-push", 12 | "publish:next": "lerna publish --preid next-$(date +%s) --dist-tag next --force-publish='*' --no-push --no-git-tag-version prepatch --ignore-prepublish --ignore-scripts --no-private -y", 13 | "disttag:release": "sh ./scripts/set-release-tag.sh", 14 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", 15 | "test": "jest", 16 | "ci": "yarn test", 17 | "lint": "prettier -w .", 18 | "prepare": "husky install" 19 | }, 20 | "lint-staged": { 21 | "*.d.ts": [ 22 | "prettier --config ./.prettierrc --write" 23 | ] 24 | }, 25 | "devDependencies": { 26 | "@tsd/typescript": "^4.7.4", 27 | "conventional-changelog-cli": "^2.2.2", 28 | "husky": "^8.0.3", 29 | "jest": "^28.1.1", 30 | "jest-runner-tsd": "^3.1.0", 31 | "lerna": "^5.0.0", 32 | "lint-staged": "13.1.0", 33 | "prettier": "^2.8.1", 34 | "typescript": "^4.6.4" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/aliauto/README.md: -------------------------------------------------------------------------------- 1 | # @mini-types/aliauto 2 | 3 | ## 如何使用 4 | 5 | 安装 `@mini-types/aliauto` 和 `@mini-types/global` 两个包 6 | 7 | ```sh 8 | npm install @mini-types/global @mini-types/aliauto --save-dev 9 | # or 10 | yarn add -D @mini-types/global @mini-types/aliauto 11 | ``` 12 | 13 | 在 `tsconfig.json` 文件中指定 `types` 配置。 14 | 15 | ```json 16 | { 17 | "compilerOptions": { 18 | "types": ["@mini-types/global", "@mini-types/aliauto"] 19 | } 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/aliauto/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/aliauto", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for AliAuto's mini program.", 5 | "scripts": {}, 6 | "miniprogram": "./", 7 | "repository": { 8 | "type": "git", 9 | "url": "git@github.com:ant-mini-program/api-typings.git" 10 | }, 11 | "keywords": [ 12 | "tinyapp", 13 | "miniprogram", 14 | "types" 15 | ], 16 | "license": "MIT", 17 | "types": "./types/index.d.ts", 18 | "files": [ 19 | "types" 20 | ], 21 | "publishConfig": { 22 | "registry": "https://registry.npmjs.org/", 23 | "access": "public" 24 | }, 25 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 26 | } 27 | -------------------------------------------------------------------------------- /packages/aliauto/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @summary 阿里车小程序域的js-api命名空间。 3 | */ 4 | declare namespace my.aliauto { 5 | export function getVehicleInfo(r: { 6 | /** 7 | * @summary 获取车辆信息。 8 | * @description 9 | * - 需要用户授权之后才能正常获取。 10 | * - 获取对象部份属性可能为空。 11 | */ 12 | success(data: { 13 | VIN: string; 14 | /** 15 | * @summary 获取车辆车架VIN号. 16 | */ 17 | engineNo: string; 18 | /** 19 | * @summary 发动机号,可能为空。 20 | */ 21 | plateNumber: string; 22 | /** 23 | * @summary 车牌号,可能为空。 24 | */ 25 | vehicleType: string; 26 | /** 27 | * @summary 车辆类型,可能为空。 28 | */ 29 | brand: string; 30 | /** 31 | * @summary 品牌,可能为空。 32 | */ 33 | energyType: string; 34 | /** 35 | * @summary 能源类型,可能为空。 36 | */ 37 | JV: string; 38 | /** 39 | * @summary 合资类型,可能为空。 40 | */ 41 | }): void; 42 | fail?(): void; 43 | }): void; 44 | export function getVehicleAccountInfo(r?: { 45 | /** 46 | * 获取车机账号 47 | */ 48 | success?(data: { 49 | id: String; 50 | /** 51 | * 车机账号id 52 | */ 53 | token: string; 54 | /** 55 | * 车机账号token,可能为空。 56 | */ 57 | }): void; 58 | fail?(): void; 59 | }): void; 60 | export function openCarInfoSettings(r?: { 61 | /** 62 | * @summary 打开车辆信息设置 63 | */ 64 | success?(): void; 65 | }): void; 66 | 67 | export function getDrivingBlock(r?: { 68 | /* 69 | * @summary 获取行车状态的是否需要限制操作。 70 | */ 71 | success?(data: { 72 | type: String; 73 | /** 74 | type=0 name=无限制, 75 | type=1 name=操作限制, 76 | type=2 name=显示限制, 77 | type=2 name=显示制限&操作制限, 78 | type=4 name=全部制限, 79 | */ 80 | name: String; 81 | /** 82 | type=0 name=无限制, 83 | type=1 name=操作限制, 84 | type=2 name=显示限制, 85 | type=2 name=显示制限&操作制限, 86 | type=4 name=全部制限, 87 | */ 88 | }): void; 89 | fail?(): void; 90 | complete?(): void; 91 | }): void; 92 | 93 | export function offDrivingBlock(): void; 94 | /* 95 | * @summary 取消监听行车限制操作状态变化。 96 | */ 97 | export function onDrivingBlock( 98 | cb: (arg: { 99 | /** 100 | * @summary 注册监听行车限制操作状态变化。。 101 | */ 102 | name: 103 | | '无限制' 104 | | '操作限制' 105 | | '显示限制' 106 | | '显示制限&操作制限' 107 | | '全部制限'; 108 | /** 109 | * @summary 限制类型值 110 | */ 111 | type: '0' | '1' | '2' | '3' | '4'; 112 | }) => void 113 | ): void; 114 | 115 | export function navigateToLocation(r?: { 116 | /* 117 | * @summary 发起当前车辆位置到目的地的导航 118 | */ 119 | latitude: number; 120 | longitude: number; 121 | mode: Number; 122 | name?: String; 123 | quickNavi?: boolean; 124 | waypoints?: Array; 125 | success?(data: Position): void; 126 | fail?(): void; 127 | complete?(): void; 128 | }): void; 129 | export function getLastLocation(r?: { 130 | /* 131 | * @summary 获取用户当前的地理位置信息。 132 | */ 133 | success?(data: Position): void; 134 | fail?(data: { 135 | code: string; 136 | /** 137 | * 2:参数错误。 138 | * 11:请确认定位相关权限已开启。 139 | * 12:网络异常,请稍后再试。 140 | * 13:定位失败,请稍后再试。 141 | * 14:业务定位超时。 142 | */ 143 | message: string; 144 | }): void; 145 | complete?(): void; 146 | }): void; 147 | export function onLocation(r?: { 148 | /* 149 | * @summary 该接口注册的回调函数接收位置信息和错误信息。 150 | */ 151 | success?(data: Position): void; 152 | fail?(data: { 153 | code: string; 154 | /** 155 | * 2:参数错误。 156 | * 11:请确认定位相关权限已开启。 157 | * 12:网络异常,请稍后再试。 158 | * 13:定位失败,请稍后再试。 159 | * 14:业务定位超时。 160 | */ 161 | message: string; 162 | }): void; 163 | complete?(): void; 164 | }): void; 165 | export function removeLocationUpdates(r?: { 166 | /* 167 | * @summary 取消my.aliauto.requestLocationUpdates 请求的用户当前位置更新。。 168 | */ 169 | success?(): void; 170 | fail?(): void; 171 | complete?(): void; 172 | }): void; 173 | export function requestGeocode(r?: { 174 | /* 175 | * @summary 根据地址查询经纬度 176 | */ 177 | address: String; 178 | success?(data: Position): void; 179 | fail?(): void; 180 | complete?(): void; 181 | }): void; 182 | export function requestLocationUpdates(r?: { 183 | /* 184 | * @summary 更新当前位置 185 | */ 186 | interval: Number; 187 | fastestInterval?: Number; 188 | priority?: Number; 189 | smallestDisplacement?: Number; 190 | timeout?: Number; 191 | needAddress?: Boolean; 192 | success?(data: Position): void; 193 | fail?(): void; 194 | complete?(): void; 195 | }): void; 196 | export function requestReverseGeocode(r?: { 197 | /* 198 | * @summary 根据经纬度查询地址。 199 | */ 200 | latitude: Number; 201 | longitude?: Number; 202 | success?(data: Array): void; 203 | fail?(): void; 204 | complete?(): void; 205 | }): void; 206 | 207 | interface Position { 208 | accuracy: number; 209 | /** 210 | * 精确度,单位米 211 | */ 212 | adCode: string; 213 | /** 214 | * 区县级别的地区代码 215 | */ 216 | address: string; 217 | /** 218 | * 地址 219 | */ 220 | altitude: Number; 221 | /** 222 | * 高度,单位米;海平面以上为正 223 | */ 224 | area: String; 225 | /** 226 | *区域名称 227 | */ 228 | bearing: Number; 229 | /** 230 | * 方位,单位度, 范围是 [0.0, 360.0) 231 | */ 232 | city: String; 233 | /** 234 | * 城市 235 | */ 236 | cityCode: String; 237 | /** 238 | * 城市级别的地区代码 239 | */ 240 | country: String; 241 | /** 242 | * 国家 243 | */ 244 | district: String; 245 | /** 246 | * 区县 247 | */ 248 | latitude: Number; 249 | /** 250 | * GPS WGS84 坐标,纬度,单位度 251 | */ 252 | longitude: Number; 253 | /** 254 | * GPS WGS84 坐标,经度,单位度 255 | */ 256 | offsetlatitude: Number; 257 | /** 258 | * GCJ-02 坐标,纬度,单位度 259 | */ 260 | offsetlongitude: Number; 261 | /** 262 | * GCJ-02 坐标,经度,单位度 263 | */ 264 | poi: String; 265 | /** 266 | * 兴趣点(POI)名称 267 | */ 268 | provider: string; 269 | /** 270 | * 地址提供者 271 | */ 272 | province: String; 273 | /** 274 | * 省份 275 | */ 276 | road: String; 277 | /** 278 | * 路名 279 | */ 280 | speed: Number; 281 | /** 282 | * 地面速度,单位米每秒 283 | */ 284 | time: Number; 285 | /** 286 | * 世界标准时间(UTC),1970 年 1 月 1 日零时以来的毫秒数 287 | */ 288 | } 289 | 290 | export function offThemeChange(): void; 291 | /* 292 | * @summary 取消监听主题风格状态变化。 293 | */ 294 | export function onThemeChange( 295 | cb: (arg: { 296 | /** 297 | * @summary 注册监听行主题风格状态变化。。 298 | */ 299 | theme: 'light' | 'dark'; 300 | }) => void 301 | ): void; 302 | export function changeCardMode(r: { cardMode: string }): void; 303 | /* 304 | * 入参:{cardMode:type} type参数为:"big" "small", "mini" 305 | */ 306 | export function currentCardMode(r?: { 307 | /* 308 | * @summary 该获取当前小程序窗口卡片形态。 309 | */ 310 | success?(data: { cardMode: 'big' | 'small' | 'mini' }): void; 311 | fail?(): void; 312 | complete?(): void; 313 | }): void; 314 | 315 | export function offCardModeChange(): void; 316 | export function onCardModeChange( 317 | cb: (arg: { 318 | /** 319 | * @summary 监听卡片形态变化。 320 | */ 321 | current: 'big' | 'small' | 'mini'; 322 | /** 323 | * @summary 当前卡片形态 324 | */ 325 | previous: 'big' | 'small' | 'mini'; 326 | /** 327 | * @summary 改变前的卡片形态。 328 | */ 329 | }) => void 330 | ): void; 331 | export function showModeChangeButton(r?: { 332 | /* 333 | * @summary 显示改变形态的按钮。 334 | */ 335 | visible: boolean; 336 | /* 337 | * 是否可见。 338 | */ 339 | shrinkCardMode: 'small' | 'mini'; 340 | /* 341 | * 卡片形态,取值"small", "mini"。 342 | */ 343 | success?(): void; 344 | fail?(): void; 345 | complete?(): void; 346 | }): void; 347 | 348 | export function say( 349 | /* 350 | * 调用系统TTS播报。 351 | */ 352 | s: { 353 | spokenText: string; 354 | writtenText: string; 355 | tips: string; 356 | } 357 | ): void; 358 | 359 | export function tradePay(s: { 360 | /** 361 | * 阿里车机支付接口。 362 | */ 363 | tradeNO: number; 364 | success?(data: { 365 | resultCode: String; 366 | /** 367 | * 支付结果码。 368 | */ 369 | }): void; 370 | fail?(): void; 371 | }): void; 372 | 373 | export function reportAnalytics(s: { 374 | /** 375 | * 需要在埋点平台提前配置。(有限支持,配合my.canIUse处理兼容). 376 | */ 377 | eventName: String; 378 | data: Object; 379 | }): void; 380 | 381 | export function createGeoFencing(s: { 382 | /** 383 | * 新增地理围栏。(有限支持,配合my.canIUse处理兼容). 384 | */ 385 | businessId: String; 386 | /** 387 | * 围栏类型 388 | */ 389 | fenceName: string; 390 | /** 391 | * 围栏唯一名称 392 | */ 393 | latitude: Number; 394 | /** 395 | * 经度 396 | */ 397 | longitude: Number; 398 | /** 399 | * 纬度 400 | */ 401 | radius?: Number; 402 | /** 403 | * 围栏半径,单位m,默认值为500。 404 | */ 405 | action: String; 406 | /** 407 | * 围栏动作,枚举值:enter 进入,exit 退出。 408 | */ 409 | success?(data: { 410 | fenceId: String; 411 | /** 412 | * 围栏唯一Id. 413 | */ 414 | businessId: String; 415 | /** 416 | * 围栏类型Id。 417 | */ 418 | }): void; 419 | fail?(): void; 420 | complete?(): void; 421 | }): void; 422 | export function getGeoFencing(s: { 423 | /** 424 | * 获取地理围栏。(有限支持,配合my.canIUse处理兼容). 425 | */ 426 | fenceId: String; 427 | /** 428 | * 围栏唯一ID 429 | */ 430 | success?(data: { 431 | fenceData: Object; 432 | /** 433 | * 地理围栏数据. 434 | */ 435 | }): void; 436 | fail?(): void; 437 | complete?(): void; 438 | }): void; 439 | export function setGeoFencing(s: { 440 | /** 441 | * 更新地理围栏。(有限支持,配合my.canIUse处理兼容). 442 | */ 443 | fenceId: String; 444 | /** 445 | * 围栏唯一ID 446 | */ 447 | action: String; 448 | /** 449 | * 围栏动作,枚举值:enter 进入,exit 退出。 450 | */ 451 | businessId?: String; 452 | /** 453 | * 围栏类型 454 | */ 455 | fenceName?: string; 456 | /** 457 | * 围栏唯一名称 458 | */ 459 | latitude?: Number; 460 | /** 461 | * 经度 462 | */ 463 | longitude?: Number; 464 | /** 465 | * 纬度 466 | */ 467 | radius?: Number; 468 | /** 469 | * 围栏半径,单位m,默认值为500。 470 | */ 471 | 472 | success?(data: { 473 | fenceId: String; 474 | /** 475 | * 围栏Id. 476 | */ 477 | businessId: String; 478 | /** 479 | * 围栏类型Id。 480 | */ 481 | }): void; 482 | fail?(): void; 483 | complete?(): void; 484 | }): void; 485 | 486 | export function onGeoFencing(s: { 487 | /** 488 | * 启用地理围栏。(有限支持,配合my.canIUse处理兼容). 489 | */ 490 | fenceId: String; 491 | /** 492 | * 围栏唯一ID 493 | */ 494 | success?(): void; 495 | fail?(): void; 496 | }): void; 497 | export function offGeoFencing(s: { 498 | /** 499 | * 停用地理围栏。(有限支持,配合my.canIUse处理兼容). 500 | */ 501 | fenceId: String; 502 | /** 503 | * 围栏唯一ID 504 | */ 505 | success?(): void; 506 | fail?(): void; 507 | }): void; 508 | } 509 | -------------------------------------------------------------------------------- /packages/alipay/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/alipay", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for Alipay's mini program.", 5 | "scripts": {}, 6 | "miniprogram": "./", 7 | "repository": { 8 | "type": "git", 9 | "url": "git@github.com:ant-mini-program/api-typings.git" 10 | }, 11 | "keywords": [ 12 | "tinyapp", 13 | "miniprogram", 14 | "types" 15 | ], 16 | "license": "MIT", 17 | "types": "./types/index.d.ts", 18 | "files": [ 19 | "types" 20 | ], 21 | "publishConfig": { 22 | "registry": "https://registry.npmjs.org/", 23 | "access": "public" 24 | }, 25 | "dependencies": { 26 | "@mini-types/global": "3.0.14", 27 | "@mini-types/my": "3.0.14" 28 | }, 29 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 30 | } 31 | -------------------------------------------------------------------------------- /packages/alipay/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | export * from '@mini-types/global/types/lib.global'; 5 | -------------------------------------------------------------------------------- /packages/global/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/global", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for Alipay's mini program.", 5 | "scripts": {}, 6 | "miniprogram": "./", 7 | "repository": { 8 | "type": "git", 9 | "url": "git@github.com:ant-mini-program/api-typings.git" 10 | }, 11 | "keywords": [ 12 | "tinyapp", 13 | "miniprogram", 14 | "types" 15 | ], 16 | "license": "MIT", 17 | "types": "./types/index.d.ts", 18 | "files": [ 19 | "types" 20 | ], 21 | "publishConfig": { 22 | "registry": "https://registry.npmjs.org/", 23 | "access": "public" 24 | }, 25 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 26 | } 27 | -------------------------------------------------------------------------------- /packages/global/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | 8 | declare namespace MiniProgram { 9 | type UnknownRecord = Record; 10 | /** 11 | * Get union key of two types 12 | */ 13 | type UnionKeys = keyof T | keyof U; 14 | /** 15 | * Get unique keys of left type. 16 | */ 17 | type UniqueLeftKeys = Exclude, keyof U>; 18 | /** 19 | * Extract left-only types. 20 | */ 21 | type UniqueLeft = { 22 | [P in UniqueLeftKeys]: T[P]; 23 | }; 24 | 25 | // 获取 mixins 数组的每一个元素的类型 26 | type TExtractValuesOfTuple = T[keyof T & number]; 27 | 28 | // 获取 methods、props、data 类型(主要就是这个三个) 29 | 30 | type TGetMixinMethods = T extends { methods?: infer M } ? M : never; 31 | 32 | type TGetMixinData = T extends { data?: infer D } ? D : never; 33 | 34 | type TGetMixinProps = T extends { props?: infer P } ? P : never; 35 | 36 | // 整合一下类型 37 | type UnionToIntersection = ( 38 | T extends any ? (x: T) => any : never 39 | ) extends (x: infer R) => any 40 | ? R 41 | : never; 42 | 43 | /** 44 | * Recursively map a type and make all properties optional. 45 | */ 46 | type RecursivePartial = { 47 | [P in keyof T]?: T[P] extends Array 48 | ? Array> 49 | : T[P] extends object 50 | ? RecursivePartial 51 | : T[P]; 52 | }; 53 | 54 | /** 55 | * Recursively map a type and make all properties optional & dynamic. 56 | */ 57 | type RecursivePartialAndDynamic = T extends object 58 | ? { 59 | [P in keyof T]?: T[P] extends Array 60 | ? Array> 61 | : T[P] extends Function 62 | ? T[P] 63 | : T[P] extends object 64 | ? RecursivePartialAndDynamic 65 | : T[P]; 66 | } 67 | : T; 68 | } 69 | -------------------------------------------------------------------------------- /packages/global/types/lib.app.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MiniProgram.App { 2 | interface ReferrerInfo { 3 | /** 4 | * 来源小程序 5 | */ 6 | appId: string; 7 | /** 8 | * 来源插件,当处于插件运行模式时可见 9 | */ 10 | sourceServiceId: string; 11 | /** 12 | * 来源小程序传过来的数据 13 | */ 14 | extraData: Record; 15 | } 16 | 17 | interface LaunchOptions< 18 | Query extends Record = Record 19 | > { 20 | /** 21 | * 当前小程序的 query,从启动参数的 query 字段解析而来 22 | */ 23 | query: Query; 24 | /** 25 | * 启动小程序的 场景值 26 | * @see https://opendocs.alipay.com/mini/framework/scene 27 | */ 28 | scene: number; 29 | /** 30 | * 当前小程序的页面地址,从启动参数 page 字段解析而来,page 忽略时默认为首页 31 | */ 32 | path: string; 33 | /** 34 | * 来源信息 35 | */ 36 | referrerInfo: ReferrerInfo; 37 | } 38 | 39 | interface UnhandledRejectionRes { 40 | /** 41 | * reject 的原因 42 | */ 43 | reason: string; 44 | /** 45 | * 被 reject 的 Promise 对象 46 | */ 47 | promise: Promise; 48 | } 49 | 50 | /** 51 | * app.js App(options) 中 options 的内部类型 52 | * ref: https://opendocs.alipay.com/mini/framework/app-detail 53 | */ 54 | interface Options { 55 | /** 56 | * 生命周期回调:监听小程序初始化 57 | * 当小程序初始化完成时触发,全局只触发一次 58 | */ 59 | onLaunch(options: LaunchOptions): void; 60 | /** 61 | * 生命周期回调:监听小程序显示 62 | * 当小程序启动,或从后台进入前台显示时触发 63 | */ 64 | onShow(options: LaunchOptions): void; 65 | /** 66 | * 生命周期回调:监听小程序隐藏 67 | * 当当前页面被隐藏时触发,例如跳转、按下设备 Home 键离开 68 | */ 69 | onHide(): void; 70 | /** 71 | * 监听小程序错误 72 | * 当小程序发生 js 错误时触发 73 | */ 74 | onError(error: string): void; 75 | /** 76 | * 全局分享配置 77 | */ 78 | onShareAppMessage(): Page.IShareAppMessage; 79 | /** 80 | * 监听 unhandledrejection 事件 81 | * 当 Promise 被 reject 且没有 reject 处理器时,会触发 onUnhandledRejection 事件 82 | */ 83 | onUnhandledRejection(res: UnhandledRejectionRes): void; 84 | /** 85 | * 全局数据 86 | */ 87 | globalData: object; 88 | } 89 | 90 | /** 91 | * Additional properties in App instance, for module augmentation 92 | */ 93 | interface IInstanceAdditionalProperties {} 94 | 95 | /** 96 | * App 的类型 97 | */ 98 | interface IApp { 99 | (opts: UserAppOptions): any; 100 | } 101 | 102 | type IAppInstance = Omit< 103 | ExtraOptions, 104 | keyof Options 105 | > & 106 | ExtraThis & 107 | IInstanceAdditionalProperties; 108 | 109 | /** 110 | * 用户可配置的 App Options 111 | */ 112 | type UserAppOptions = Partial< 113 | Options 114 | > & 115 | Partial< 116 | UniqueLeft, Options> 117 | > & { 118 | [P in keyof ExtraOptions]: P extends keyof Options 119 | ? unknown 120 | : ExtraOptions[P]; 121 | } & ThisType>; 122 | 123 | interface Constructor { 124 | = {}>( 125 | opts: UserAppOptions< 126 | ExtraThis & IGlobalMiniProgramExtraThis4App, 127 | ExtraOptions 128 | > 129 | ): void; 130 | } 131 | 132 | interface GetApp { 133 | < 134 | ExtraThis = {}, 135 | ExtraOptions extends Record = {} 136 | >(): IAppInstance< 137 | ExtraThis & IGlobalMiniProgramExtraThis4App, 138 | ExtraOptions 139 | >; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /packages/global/types/lib.component.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MiniProgram.Component { 2 | /** 3 | * Additional properties in Component instance, for module augmentation 4 | */ 5 | interface IComponentInstanceAdditionalProperties< 6 | ExtraOptions extends UnknownRecord 7 | > {} 8 | 9 | interface ILifetimes { 10 | /** 11 | * 在组件实例刚刚被创建时执行 12 | */ 13 | created(): void; 14 | /** 15 | * 在组件实例进入页面节点树时执行 16 | */ 17 | attached(): void; 18 | /** 19 | * 在组件在视图层布局完成后执行 20 | */ 21 | ready(): void; 22 | /** 23 | * 在组件实例被移动到节点树另一个位置时执行 24 | */ 25 | moved(): void; 26 | /** 27 | * 在组件实例被从页面节点树移除时执行 28 | */ 29 | detached(): void; 30 | } 31 | 32 | interface IRelationOption { 33 | /** 34 | * 与目标组件的相对关系 35 | */ 36 | type: 'parent' | 'child' | 'ancestor' | 'descendant'; 37 | /** 38 | * 关系生命周期函数,目标组件建立时触发,触发时机在组件 attached 生命周期之后。 39 | */ 40 | linked?(target: BaseInstance): void; 41 | /** 42 | * 关系生命周期函数,目标组件移动时触发,触发时机在组件 moved 生命周期之后。 43 | */ 44 | linkChanged?(target: BaseInstance): void; 45 | /** 46 | * 关系生命周期函数,目标组件销毁时触发,触发时机在组件 detached 生命周期之后 47 | */ 48 | unlinked?(target: BaseInstance): void; 49 | /** 50 | * 根据组件使用的 Mixin 来建立关系 51 | * 如果这一项被设置,则它表示关联的目标节点所应具有的Mixin实例,所有拥有这一Mixin实例的组件节点都会被关联 52 | */ 53 | target?: string; 54 | } 55 | 56 | /** 57 | * component\/*\/index.js Component(options) 中 options 的内部类型 58 | * ref: https://opendocs.alipay.com/mini/framework/component_object 59 | */ 60 | interface IOptions< 61 | Data, 62 | Props, 63 | Methods, 64 | ExtraOptions extends UnknownRecord, 65 | Mixins extends Array> 66 | > { 67 | /** 68 | * 组件内部状态 69 | */ 70 | data: Data | ((this: void) => Data); 71 | /** 72 | * 为外部传入的数据设置默认值 73 | */ 74 | props: Props; 75 | /** 76 | * 组件生命周期函数,组件创建时触发 77 | * @version 1.14.0+ 78 | */ 79 | onInit(): void; 80 | /** 81 | * 组件生命周期函数,组件创建时和更新前触发 82 | * @version 1.14.0+ 83 | */ 84 | deriveDataFromProps(nextProps: Partial): void; 85 | /** 86 | * 组件生命周期函数,组件创建完毕时触发 87 | */ 88 | didMount(): void; 89 | /** 90 | * 组件生命周期函数,组件更新完毕时触发 91 | */ 92 | didUpdate(prevProps: Partial, prevData: Partial): void; 93 | /** 94 | * 组件生命周期函数,组件删除时触发 95 | */ 96 | didUnmount(): void; 97 | /** 98 | * 组件间代码复用机制 99 | */ 100 | mixins: Mixins; 101 | /** 102 | * 组件的方法,可以是事件响应函数或任意的自定义方法 103 | * Object of Functions 104 | */ 105 | methods: Methods; 106 | /** 107 | * 指定组件被ref引用时的返回值 108 | * @version 1.18.0+ 109 | */ 110 | ref(): void; 111 | /** 112 | * 监听所属页面除onShareAppMessage外的页面的生命周期函数以及页面事件处理函数。 113 | * @version 2.8.5 114 | */ 115 | pageEvents: Partial; 116 | /** 117 | * 开启某些功能项 118 | */ 119 | options: Partial<{ 120 | /** 121 | * 开启虚拟化自定义组件节点,默认值为 true 122 | * @version 2.8.0 123 | */ 124 | virtualHost: boolean; 125 | /** 126 | * 开启 observers 数据变化观测器 127 | * @version 2.8.1 128 | */ 129 | observers: boolean; 130 | /** 131 | * 开启 lifetimes 节点树维度生命周期 132 | * @version 2.8.5 133 | */ 134 | lifetimes: boolean; 135 | /** 136 | * 开启 relations 组件间关系 137 | * @version 2.8.5 138 | */ 139 | relations: boolean; 140 | /** 141 | * 开启 externalClasses 外部样式类 142 | * @version 2.8.5 143 | */ 144 | externalClasses: boolean; 145 | }>; 146 | /** 147 | * 数据变化观测器,观测和响应任何属性和数据字段的变化 148 | * @version 2.8.1 149 | */ 150 | observers: Record void>; 151 | /** 152 | * 节点树维度生命周期 153 | * @version 2.8.5 154 | */ 155 | lifetimes: Partial; 156 | /** 157 | * 组件间关系 158 | * @version 2.8.5 159 | */ 160 | relations: Record; 161 | /** 162 | * 组件接受的外部样式类 163 | * @version 2.8.5 164 | */ 165 | externalClasses: string[]; 166 | } 167 | interface IInstanceProperties { 168 | /** 169 | * 组件路径 170 | */ 171 | readonly is: string; 172 | /** 173 | * 组件 id,可直接在组件 axml 中渲染值 174 | */ 175 | readonly $id: number; 176 | /** 177 | * 组件所属页面实例 178 | */ 179 | readonly $page: Record; 180 | /** 181 | * 自定义组件路由对象 182 | * @description 可获得当前自定义组件的路由对象,路由方法与全局路由方法功能相同,唯一区别在于调用时,相对路径是相对于该自定义组件 183 | * @version 2.7.22 184 | */ 185 | readonly router: Shared.IRouter; 186 | /** 187 | * 自定义组件所在页面路由对象 188 | * @description 可获得当前自定义组件所在页面的路由对象,路由方法与全局路由方法功能相同,唯一区别在于调用时,相对路径是相对于所在页面 189 | * @version 2.7.22 190 | */ 191 | readonly pageRouter: Shared.IRouter; 192 | } 193 | 194 | interface IInstanceMethods { 195 | /** 196 | * 将数据从逻辑层发送到视图层 197 | * @param data 198 | * @param callback 199 | */ 200 | setData( 201 | data: RecursivePartialAndDynamic & Record, 202 | callback?: () => void 203 | ): void; 204 | /** 205 | * $spliceData 同样用于将数据从逻辑层发送到视图层,但是相比于 setData,在处理长列表的时候,其具有更高的性能。 206 | * @param data 207 | * @param callback 208 | * @version 1.7.2+ 可以使用 my.canIUse('page.$spliceData') 做兼容性处理 209 | */ 210 | $spliceData( 211 | data: RecursivePartialAndDynamic & Record, 212 | callback?: () => void 213 | ): void; 214 | /** 215 | * 选取当前组件的创建者(即 AXML 中定义了此组件的组件),返回它的组件实例对象(会被 `ref` 影响)。 216 | * 217 | * @version 2.7.22 218 | * @returns undefined | null | 页面 | 自定义组件 | 用户 ref 的 Object 219 | */ 220 | selectOwnerComponent(): BaseInstance; 221 | /** 222 | * 选取当前组件在事件冒泡路径上的父组件,返回它的组件实例对象(会被 `ref` 影响)。 223 | * 224 | * @version 2.7.22 225 | * @returns undefined | null | 页面 | 自定义组件 | 用户 ref 的 Object 226 | */ 227 | selectComposedParentComponent(): BaseInstance; 228 | /** 229 | * 检查组件是否具有 mixin(须是通过Mixin()创建的mixin实例)。 230 | * @description 若自定义组件注册时传入了ref以指定组件返回值,则可通过hasMixin('ref')检查到 231 | * @version 2.8.2 232 | * @return boolean 233 | * @see https://opendocs.alipay.com/mini/framework/component_object#%E7%BB%84%E4%BB%B6%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95 234 | */ 235 | hasMixin(mixin: Mixin.IMixinIdentifier): boolean; 236 | /** 237 | * 获取这个关系所对应的所有关联节点,参见 组件间关系 238 | * @version 2.8.5 239 | */ 240 | getRelationNodes(relationKey: string): BaseInstance[]; 241 | } 242 | /** 243 | * Public instance 244 | */ 245 | type IInstance< 246 | Data, 247 | Props, 248 | Methods, 249 | ExtraThis, 250 | ExtraOptions extends UnknownRecord, 251 | Mixins extends Array> 252 | > = { 253 | data: Data & 254 | UnionToIntersection>>; 255 | props: Readonly< 256 | Props & UnionToIntersection>> 257 | >; 258 | } & Methods & 259 | UnionToIntersection>> & 260 | ExtraThis & 261 | Omit< 262 | ExtraOptions, 263 | keyof IOptions 264 | > & 265 | IComponentInstanceAdditionalProperties & 266 | IInstanceProperties & 267 | IInstanceMethods & 268 | Shared.IInstanceSharedMethods; 269 | 270 | type BaseInstance = IInstance< 271 | UnknownRecord, 272 | UnknownRecord, 273 | UnknownRecord, 274 | UnknownRecord, 275 | UnknownRecord, 276 | [] 277 | >; 278 | interface Constructor { 279 | < 280 | Data = UnknownRecord, 281 | Props = UnknownRecord, 282 | Methods = UnknownRecord, 283 | ExtraThis = UnknownRecord, 284 | ExtraOptions extends Record = UnknownRecord, 285 | Mixins extends Array< 286 | Mixin.IMixin4Legacy | ReturnType 287 | > = any[] 288 | >( 289 | opts: { 290 | [P in keyof ExtraOptions]: P extends keyof IOptions< 291 | Data, 292 | Props, 293 | Methods, 294 | ExtraOptions, 295 | Mixins 296 | > 297 | ? unknown 298 | : ExtraOptions[P]; 299 | } & Partial> & 300 | ThisType< 301 | IInstance< 302 | Data, 303 | Props, 304 | Methods, 305 | ExtraThis & IGlobalMiniProgramExtraThis4Component, 306 | ExtraOptions, 307 | Mixins 308 | > 309 | > 310 | ): void; 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /packages/global/types/lib.global.d.ts: -------------------------------------------------------------------------------- 1 | export type IAppOnLaunchOptions> = 2 | MiniProgram.App.LaunchOptions; 3 | 4 | export interface IRequirePluginAsync< 5 | Target extends Record = Record 6 | > { 7 | (pluginName: K): Promise; 8 | (pluginName: string): Promise; 9 | } 10 | export interface IRequirePlugin< 11 | Target extends Record = Record 12 | > { 13 | (pluginName: K): Target[K]; 14 | (pluginName: string): Result; 15 | async: IRequirePluginAsync; 16 | } 17 | 18 | export type IMixin4Legacy< 19 | Data, 20 | Props, 21 | Methods, 22 | ExtraThis = MiniProgram.UnknownRecord, 23 | ExtraOptions extends MiniProgram.UnknownRecord = MiniProgram.UnknownRecord 24 | > = MiniProgram.Mixin.IMixin4Legacy< 25 | Data, 26 | Props, 27 | Methods, 28 | ExtraThis, 29 | ExtraOptions 30 | >; 31 | 32 | export interface Require { 33 | (path: string): T; 34 | (path: string, cb?: (o: T) => void): void; 35 | 36 | async(path: string): Promise; 37 | } 38 | 39 | declare global { 40 | /** 41 | * Extra `this` for Component instance. 42 | */ 43 | interface IGlobalMiniProgramExtraThis4Component {} 44 | 45 | /** 46 | * Extra `this` for Page instance. 47 | */ 48 | interface IGlobalMiniProgramExtraThis4Page {} 49 | 50 | /** 51 | * Extra `this` for App instance. 52 | */ 53 | interface IGlobalMiniProgramExtraThis4App {} 54 | 55 | /** 56 | * 使用插件提供的 JS 接口,函数返回值为 \`插件\` 通过 \`main\` 字段暴露的 JS 接口。 57 | */ 58 | const requirePlugin: IRequirePlugin; 59 | 60 | const require: Require; 61 | 62 | /** 63 | * App's constructor 64 | * @link https://opendocs.alipay.com/mini/framework/app-detail 65 | */ 66 | const App: MiniProgram.App.Constructor; 67 | 68 | /** 69 | * Get App. 70 | * @link https://opendocs.alipay.com/mini/framework/get-app 71 | */ 72 | const getApp: MiniProgram.App.GetApp; 73 | 74 | /** 75 | * Get Current Pages 76 | * @link https://opendocs.alipay.com/mini/framework/getcurrentpages 77 | */ 78 | const getCurrentPages: MiniProgram.Page.GetCurrentPages; 79 | 80 | /** 81 | * Page's constructor 82 | * @link https://opendocs.alipay.com/mini/framework/page-detail 83 | */ 84 | const Page: MiniProgram.Page.Constructor; 85 | 86 | /** 87 | * Component's constructor 88 | * @link https://opendocs.alipay.com/mini/framework/component_object 89 | */ 90 | const Component: MiniProgram.Component.Constructor; 91 | 92 | /** 93 | * 注册一个 `mixin`,接受一个 `Object` 类型的参数。 94 | * @version 2.8.2 95 | * @link https://opendocs.alipay.com/mini/05bchn 96 | */ 97 | const Mixin: MiniProgram.Mixin.Constructor; 98 | } 99 | -------------------------------------------------------------------------------- /packages/global/types/lib.mixin.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MiniProgram.Mixin { 2 | /** 3 | * 传统的组件间代码复用,仅Component的mixins参数支持传入,Mixin参数mixins 则只支持传入Mixin()的返回值 4 | */ 5 | type IMixin4Legacy< 6 | Data extends UnknownRecord, 7 | Props extends UnknownRecord, 8 | Methods extends UnknownRecord, 9 | ExtraThis extends UnknownRecord = UnknownRecord, 10 | ExtraOptions extends UnknownRecord = UnknownRecord 11 | > = Partial< 12 | MiniProgram.Component.IOptions 13 | > & 14 | ThisType< 15 | MiniProgram.Component.IInstance< 16 | Data, 17 | Props, 18 | Methods, 19 | ExtraThis & IGlobalMiniProgramExtraThis4Component, 20 | ExtraOptions, 21 | [] 22 | > 23 | >; 24 | /** 25 | * Mixin() 返回值 26 | */ 27 | type IMixinIdentifier = string; 28 | 29 | type IMixinDefinitionFilter = < 30 | T extends 31 | | Component.IOptions 32 | | IMixinOptions 33 | | Page.IOptions 34 | >( 35 | /** 使用该 mixin 的 component/mixin 的定义对象 */ 36 | defFields: T, 37 | /** 该 mixin 所使用的 mixin 的 definitionFilter 函数列表 */ 38 | definitionFilterArr?: IMixinDefinitionFilter[] | void 39 | ) => void; 40 | 41 | /** 42 | * Mixin构造器参数 43 | */ 44 | type IMixinOptions< 45 | Data, 46 | Props, 47 | Methods, 48 | ExtraThis, 49 | ExtraOptions extends UnknownRecord, 50 | Mixins extends Array> 51 | > = { 52 | [P in keyof ExtraOptions]: P extends 53 | | keyof Component.IOptions 54 | | 'definitionFilter' 55 | | 'mixins' 56 | ? unknown 57 | : ExtraOptions[P]; 58 | } & Omit< 59 | Partial< 60 | Component.IOptions 61 | >, 62 | 'ref' | 'options' | 'externalClasses' 63 | > & 64 | Partial<{ 65 | /** 66 | * 定义段过滤器,用于自定义组件扩展 67 | */ 68 | definitionFilter: IMixinDefinitionFilter; 69 | /** 70 | * 组件间代码复用,用于Mixin()的mixins 只支持传入Mixin()注册生成的返回值。不支持传入 js Object 71 | */ 72 | mixins: Mixins; 73 | }> & 74 | ThisType< 75 | Component.IInstance< 76 | Data, 77 | Props, 78 | Methods, 79 | ExtraThis, 80 | ExtraOptions, 81 | IMixinIdentifier[] 82 | > 83 | >; 84 | 85 | interface Constructor { 86 | < 87 | Data = UnknownRecord, 88 | Props = UnknownRecord, 89 | Methods = UnknownRecord, 90 | ExtraThis = UnknownRecord, 91 | ExtraOptions extends UnknownRecord = UnknownRecord, 92 | Mixins extends IMixinIdentifier[] = [] 93 | >( 94 | options: IMixinOptions< 95 | Data, 96 | Props, 97 | Methods, 98 | ExtraThis & IGlobalMiniProgramExtraThis4Component, 99 | ExtraOptions, 100 | Mixins 101 | > 102 | ): IMixinIdentifier; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /packages/global/types/lib.page.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MiniProgram.Page { 2 | interface IOnResizeEvent { 3 | /** 4 | * 窗口尺寸 5 | */ 6 | size: { 7 | /** 8 | * 窗口宽度 9 | */ 10 | windowWidth: number; 11 | /** 12 | * 窗口高度 13 | */ 14 | windowHeight: number; 15 | }; 16 | } 17 | interface IKeyboardHeightEvent { 18 | /** 19 | * 键盘高度 20 | */ 21 | height: number; 22 | } 23 | interface ITabItemTapEvent { 24 | /** 25 | * 点击来源。 26 | */ 27 | from: string; 28 | /** 29 | * 被点击 tabItem 的页面路径。 30 | */ 31 | pagePath: string; 32 | /** 33 | * 被点击 tabItem 的按钮文字。 34 | */ 35 | text: string; 36 | /** 37 | * 被点击 tabItem 的序号,从 0 开始。 38 | */ 39 | index: number; 40 | } 41 | interface ISelectedTabItemTapEvent { 42 | /** 43 | * 被点击 tabItem 的页面路径。 44 | */ 45 | pagePath: string; 46 | /** 47 | * 被点击 tabItem 的按钮文字。 48 | */ 49 | text: string; 50 | /** 51 | * 被点击 tabItem 的序号,从 0 开始。 52 | */ 53 | index: number; 54 | } 55 | 56 | interface IPageScrollEvent { 57 | /** 58 | * 页面滚动距离。 59 | */ 60 | scrollTop: number; 61 | /** 62 | * 页面内容高度。 63 | */ 64 | scrollHeight: number; 65 | } 66 | 67 | interface IPullDownRefreshEvent { 68 | /** 69 | * 触发原 70 | * @description 71 | * - manual: 下拉事件通过 my.startPullDownRefresh 触发 72 | * - code: 下拉事件用通过户下拉触发 73 | */ 74 | from: 'manual' | 'code'; 75 | } 76 | interface IShareAppMessageEvent { 77 | /** 78 | * 触发来源 79 | * @description 80 | * - button 页面分享按钮触发 81 | * - menu 右上角分享按钮触 82 | * - code 执行 my.showSharePanel 触发 83 | * @version 1.10.0 84 | */ 85 | from: 'button' | 'menu' | 'code'; 86 | /** 87 | * 如果 from 值为 button,则 target 为触发这次分享的 button,否则为 undefined。 88 | * @version 1.10.0 89 | */ 90 | target: object; 91 | /** 92 | * 页面中包含 web-view 组件时,返回当前 web-view 的 URL。 93 | * @version 1.6.0 94 | */ 95 | webViewUrl: string; 96 | } 97 | 98 | interface IShareAppMessage { 99 | title: string; 100 | desc: string; 101 | path: string; 102 | } 103 | /** 104 | * 页面事件处理对象 105 | */ 106 | interface Events { 107 | /** 108 | * 页面加载时触发 109 | * @param query 打开当前页面路径中的参数 110 | * @see https://opendocs.alipay.com/mini/03durs 111 | */ 112 | onLoad(query: unknown): void; 113 | /** 114 | * 页面显示时/切入前台时触发 115 | */ 116 | onShow(): void; 117 | /** 118 | * 页面初次渲染完成时触发 119 | */ 120 | onReady(): void; 121 | /** 122 | * 页面隐藏时/切入后台时触发 123 | */ 124 | onHide(): void; 125 | /** 126 | * 页面卸载时触发 127 | * @version 2.8.5 128 | */ 129 | onUnload(): void; 130 | /** 131 | * 点击标题触发 132 | */ 133 | onTitleClick(): void; 134 | /** 135 | * 点击导航栏额外图标触发 136 | * @see 设置额外图标: https://opendocs.alipay.com/mini/api/optionmenu 137 | */ 138 | onOptionMenuClick(): void; 139 | /** 140 | * 页面下拉时触发 141 | * @description 需要先在 app.json 的 window 选项中开启 pullRefresh 。当处理完数据刷新后,my.stopPullDownRefresh 可以停止当前页面的下拉刷新。 142 | * @param event 页面下拉事件 143 | * @see https://opendocs.alipay.com/mini/framework/page-detail#onPullDownRefresh(%7Bfrom%3A%20manual%7Ccode%7D) 144 | */ 145 | onPullDownRefresh(event: IPullDownRefreshEvent): void; 146 | /** 147 | * 点击 tabItem(非当前) 时触发 148 | * @param event 点击 tabItem(非当前)事件 149 | */ 150 | onTabItemTap: (event: ITabItemTapEvent) => void; 151 | /** 152 | * 页面滚动时触发。 153 | * @param event 页面滚动事件 154 | */ 155 | onPageScroll: (event: IPageScrollEvent) => void; 156 | /** 157 | * 页面被拉到底部时触发 158 | * @description 159 | * - onReachBottom() 上拉触底时才会触发,如果页面已经在页面底部继续上拉是不会再次触发。 160 | * - 可配合 my.pageScrollTo 向上滚动一点位置或者在底部增加数据等方式让页面不处在底部位置达到可以连续上拉触发 onReachBottom()的效果。 161 | * - 可在应用配置(app.json)通过 onReachBottomDistance 配置项 自定义 页面上拉触底时触发时距离页面底部的距离,单位为 px。 162 | */ 163 | onReachBottom(): void; 164 | /** 165 | * 点击非当前 tabItem 前触发 166 | */ 167 | beforeTabItemTap(): void; 168 | /** 169 | * 键盘高度变化时触发 170 | * @param event 键盘高度变化事件 171 | */ 172 | onKeyboardHeight(event: IKeyboardHeightEvent): void; 173 | /** 174 | * 导航栏左侧返回按钮(以及 Android 系统返回键)被点击时触发 175 | */ 176 | onBack: () => void; 177 | /** 178 | * window尺寸改变时触发 179 | * @version 1.16.0 180 | */ 181 | onResize(event: IOnResizeEvent): void; 182 | /** 183 | * 点击当前 tabItem 后触发。 184 | * @param event 点击当前 tabItem 事件 185 | * @version 2.7.2 186 | */ 187 | onSelectedTabItemTap: (event: ISelectedTabItemTapEvent) => void; 188 | } 189 | 190 | /** 191 | * pages\/*\/index.js Page(options) 中 options 的内部类型 192 | * ref: https://opendocs.alipay.com/mini/framework/app-detail 193 | */ 194 | interface IOptions { 195 | /** 196 | * 初始数据或返回初始化数据的函数 197 | */ 198 | data: Data | ((this: void) => Data); 199 | /** 200 | * 页面加载时触发 201 | * @param query 打开当前页面路径中的参数 202 | * @see https://opendocs.alipay.com/mini/03durs 203 | */ 204 | onLoad(query: unknown): void; 205 | /** 206 | * 页面显示时/切入前台时触发 207 | */ 208 | onShow(): void; 209 | /** 210 | * 页面初次渲染完成时触发 211 | */ 212 | onReady(): void; 213 | /** 214 | * 页面隐藏时/切入后台时触发 215 | */ 216 | onHide(): void; 217 | /** 218 | * 页面卸载时触发 219 | */ 220 | onUnload(): void; 221 | /** 222 | * 在 Page 中定义 onShareAppMessage 函数,设置该页面的分享信息。 223 | * @description 224 | * 开发者可通过传入参数自定义小程序分享内容(例如:标题、描述、图片),用户通过点击或者复制分享的内容可以快速打开小程序,进入指定页面。目前支持的分享渠道有:支付宝朋友动态、支付宝好友、钉钉、新浪微博、微信、QQ。 225 | * - 每个 Page 页面的右上角菜单中默认有 分享 按钮。 226 | * - 用户点击分享按钮的时候会调用。 227 | * - 要求返回一个对象(Object)类型,用于自定义该页面的分享信息(如果未定义该回调,会使用默认分享信息,不影响分享功能)。 228 | * - 若定义该回调,但未返回对象(Object)类型,会导致默认分享不可用。 229 | * - 分享图片中的二维码的有效期为 60 天,若需要长期有效的二维码,请登录 开放平台控制台 > 我的应用 > 进入小程序应用详情页 > 小程序码 中生成。 230 | * - 小程序在 1.1.0 版本中开始支持 open-type 为 share 的按钮触发分享。 231 | * - 从基础库 1.24.13、2.6.7 版本开始支持 async 写法,可通过 my.canIUse('page.onShareAppMessage.async') 检测是否支持。 232 | * @see https://opendocs.alipay.com/mini/framework/page-detail#onShareAppMessage(options%3A%20Object) 233 | */ 234 | onShareAppMessage( 235 | event: IShareAppMessageEvent 236 | ): IShareAppMessage | Promise; 237 | /** 238 | * 点击标题触发 239 | */ 240 | onTitleClick(): void; 241 | /** 242 | * 点击导航栏额外图标触发 243 | * @see 设置额外图标: https://opendocs.alipay.com/mini/api/optionmenu 244 | * @version 1.3.0 245 | */ 246 | onOptionMenuClick: () => void; 247 | /** 248 | * 页面下拉时触发 249 | * @description 需要先在 app.json 的 window 选项中开启 pullRefresh 。当处理完数据刷新后,my.stopPullDownRefresh 可以停止当前页面的下拉刷新。 250 | * @param event 页面下拉事件 251 | * @see https://opendocs.alipay.com/mini/framework/page-detail#onPullDownRefresh(%7Bfrom%3A%20manual%7Ccode%7D) 252 | */ 253 | onPullDownRefresh(event: IPullDownRefreshEvent): void; 254 | /** 255 | * 点击 tabItem(非当前) 时触发 256 | * @param event 点击 tabItem(非当前)事件 257 | * @version 1.11.0 258 | */ 259 | onTabItemTap: (event: ITabItemTapEvent) => void; 260 | /** 261 | * 页面滚动时触发。 262 | * @param event 页面滚动事件 263 | */ 264 | onPageScroll: (event: IPageScrollEvent) => void; 265 | /** 266 | * 页面被拉到底部时触发 267 | * @description 268 | * - onReachBottom() 上拉触底时才会触发,如果页面已经在页面底部继续上拉是不会再次触发。 269 | * - 可配合 my.pageScrollTo 向上滚动一点位置或者在底部增加数据等方式让页面不处在底部位置达到可以连续上拉触发 onReachBottom()的效果。 270 | * - 可在应用配置(app.json)通过 onReachBottomDistance 配置项 自定义 页面上拉触底时触发时距离页面底部的距离,单位为 px。 271 | */ 272 | onReachBottom(): void; 273 | /** 274 | * 事件处理函数对象 275 | * @version 1.13.7 276 | */ 277 | events: Partial; 278 | /** 279 | * 开启某些功能项 280 | */ 281 | options: { 282 | /** 283 | * 开启 observers 数据变化观测器 284 | */ 285 | observers: boolean; 286 | }; 287 | /** 288 | * 数据变化观测器,观测和响应任何数据字段的变化。 289 | * @version 2.8.1 290 | */ 291 | observers: Record void>; 292 | /** 293 | * 组件间代码复用机制,只支持传入 Mixin() 实例。 294 | * @version 2.8.5 295 | */ 296 | mixins: Mixin.IMixinIdentifier[]; 297 | } 298 | 299 | /** 300 | * Additional properties in Page instance, for module augmentation 301 | */ 302 | interface IInstanceAdditionalProperties {} 303 | 304 | interface IInstanceProperties { 305 | /** 306 | * Page 路径,对应 app.json 中配置的路径值,类型为 String。这是一个只读属性。 307 | * @readonly 308 | */ 309 | readonly route: string; 310 | /** 311 | * 页面路由对象 312 | * @description 可获得当前页面的路由对象,路由方法与全局路由方法功能相同,唯一区别在于调用时,相对路径是相对于该页面 313 | * @version 2.7.22 314 | */ 315 | readonly router: Shared.IRouter; 316 | /** 317 | * 页面路由对象 318 | * @description 同 router, 可获得当前页面的路由对象,路由方法与全局路由方法功能相同,唯一区别在于调用时,相对路径是相对于该页面 319 | * @version 2.7.22 320 | */ 321 | readonly pageRouter: Shared.IRouter; 322 | } 323 | 324 | type IInstanceSharedMethods = Shared.IInstanceSharedMethods; 325 | 326 | interface IInstanceMethods { 327 | /** 328 | * 将数据从逻辑层发送到视图层 329 | * @param data 330 | * @param callback 331 | */ 332 | setData( 333 | data: RecursivePartialAndDynamic, 334 | callback?: () => void 335 | ): void; 336 | /** 337 | * $spliceData 同样用于将数据从逻辑层发送到视图层,但是相比于 setData,在处理长列表的时候,其具有更高的性能。 338 | * @param data 339 | * @param callback 340 | * @version 1.7.2+ 可以使用 my.canIUse('page.$spliceData') 做兼容性处理 341 | */ 342 | $spliceData( 343 | data: RecursivePartialAndDynamic, 344 | callback?: () => void 345 | ): void; 346 | /** 347 | * 批量更新数据。 348 | * @param callback 349 | * @version 1.14.0+ 可以使用 my.canIUse('page.$batchedUpdates') 做兼容性处理 350 | */ 351 | $batchedUpdates(callback: () => void): void; 352 | /** 353 | * 获取 通信通道 EventChannel 354 | * @description 355 | * - 如果一个页面由另一个页面通过 my.navigateTo 打开,这两个页面间将建立一条通信通道: 356 | * - 被打开的页面可以通过 this.getOpenerEventChannel() 方法来获得一个 EventChannel 对象。 357 | * - my.navigateTo 的 success 回调中也包含一个 EventChannel 对象。 358 | * - 这两个 EventChannel 对象间可以使用 emit 和 on 方法相互发送、监听事件。 359 | * @version 2.7.7 360 | * @see https://opendocs.alipay.com/mini/api/eventchannel 361 | */ 362 | getOpenerEventChannel(): Shared.EventChannel; 363 | /** 364 | * 检查组件是否具有 mixin(须是通过Mixin()创建的mixin实例)。 365 | * @version 2.8.5 366 | * @return boolean 367 | * @see https://opendocs.alipay.com/mini/framework/page-detail#hasMixin 368 | */ 369 | hasMixin(mixin: Mixin.IMixinIdentifier): boolean; 370 | } 371 | 372 | /** 373 | * `this` type of life cycle hooks in App. 374 | */ 375 | type IInstance = { 376 | data: Data & UnknownRecord; 377 | } & ExtraThis & 378 | Omit> & 379 | IInstanceProperties & 380 | IInstanceSharedMethods & 381 | IInstanceMethods & 382 | IInstanceAdditionalProperties; 383 | 384 | interface Constructor { 385 | < 386 | Data = {}, 387 | ExtraThis = {}, 388 | ExtraOptions extends Record = {} 389 | >( 390 | options: Partial< 391 | UniqueLeft< 392 | UniqueLeft, 393 | IOptions 394 | > 395 | > & { 396 | [P in keyof ExtraOptions]: P extends keyof IOptions 397 | ? unknown 398 | : ExtraOptions[P]; 399 | } & Partial> & 400 | ThisType> 401 | ): void; 402 | } 403 | interface GetCurrentPages { 404 | (): Array>; 405 | } 406 | } 407 | -------------------------------------------------------------------------------- /packages/global/types/lib.shared.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MiniProgram.Shared { 2 | interface SetUpdatePerformanceListenerOption { 3 | /** 4 | * 是否返回变更的 data 字段信息 5 | */ 6 | withDataPaths?: WithDataPath; 7 | } 8 | 9 | interface UpdatePerformanceListener { 10 | (res: ISetUpdatePerformanceListenerResult): void; 11 | } 12 | 13 | interface ISingleSetDataPerformanceInfo { 14 | /** setData ID */ 15 | id: number; 16 | /** 加入到队列的时间 */ 17 | pendingStartTimestamp: number; 18 | /** 本次更新的 data,所包含的 key 值 */ 19 | dataPaths?: WithDataPath extends true ? string[] : undefined; 20 | } 21 | 22 | interface ISetUpdatePerformanceListenerResult { 23 | /** 其他组件更新,而导致的更新 */ 24 | isMergedUpdate: boolean; 25 | /** 更新批次 ID */ 26 | updateProcessId: number; 27 | /** 父更新批次 ID */ 28 | parentUpdateProcessId?: number; 29 | /** 30 | * 本批次合并之后的 data,所包含的 key 值 31 | */ 32 | dataPaths?: WithDataPath extends true ? string[] : undefined; 33 | /** 组件第一条数据,加入到队列的时间 */ 34 | pendingStartTimestamp?: number; 35 | /** render 侧接收到,data 数据的时间 */ 36 | updateStartTimestamp?: number; 37 | /** render 侧完成 UI 更新的时间 */ 38 | updateEndTimestamp?: number; 39 | /** 40 | * 本批次所有 setData 的数据信息 41 | */ 42 | dataList: ISingleSetDataPerformanceInfo[]; 43 | } 44 | 45 | interface IMediaQueryObserver { 46 | /** 47 | * 开始监听页面 media query 变化情况 48 | * @param descriptor media query 描述符 49 | * @param callback 监听 media query 状态变化的回调函数 50 | * @see https://opendocs.alipay.com/mini/05awpq 51 | */ 52 | observe: ( 53 | descriptor: IMediaQueryObserveDescriptor, 54 | callback: IMediaQueryObserveCallback 55 | ) => void; 56 | /** 57 | * 停止监听。回调函数将不再触发 58 | * @see https://opendocs.alipay.com/mini/05bb9o 59 | */ 60 | disconnect: () => void; 61 | } 62 | 63 | type IMediaQueryObserveCallback = ( 64 | payload: IMediaQueryObserveCallbackResponse 65 | ) => void; 66 | 67 | interface IMediaQueryObserveCallbackResponse { 68 | /** 69 | * 页面的当前状态是否满足所指定的 media query 70 | */ 71 | matches: boolean; 72 | } 73 | interface IMediaQueryObserveDescriptor { 74 | /** 75 | * 页面最小宽度( px 为单位) 76 | */ 77 | minWidth?: number; 78 | /** 79 | * 页面最大宽度( px 为单位) 80 | */ 81 | maxWidth?: number; 82 | /** 83 | * 页面宽度( px 为单位) 84 | */ 85 | width?: number; 86 | /** 87 | * 页面最小高度( px 为单位) 88 | */ 89 | minHeight?: number; 90 | /** 91 | * 页面最大高度( px 为单位) 92 | */ 93 | maxHeight?: number; 94 | /** 95 | * 页面高度( px 为单位) 96 | */ 97 | height?: number; 98 | /** 99 | * 屏幕方向( landscape 或 portrait ) 100 | * - landscape viewport 处于横向,即宽度大于高度。 101 | * - portrait viewport 处于纵向,即高度大于等于宽度。 102 | */ 103 | orientation?: 'landscape' | 'portrait'; 104 | } 105 | 106 | interface IRouter { 107 | navigateTo: (object: { 108 | /** 109 | * 需要跳转的目标页面路径 110 | * @description 路径后可以带参数, 目标路径必须为应用内非 tabbar 的,路径与参数之间使用 ?分隔,参数键与参数值用=相连,不同参数必须用&分隔 111 | */ 112 | url: string; 113 | /** 114 | * 页面间通信接口,用于监听被打开页面发送到当前页面的数据 115 | */ 116 | events?: IMyNavigateToEvents; 117 | /** 118 | * 接口调用成功的回调函数 119 | */ 120 | success?(data: { 121 | /** 122 | * 和被打开页面进行通信 123 | */ 124 | eventChannel: EventChannel; 125 | }): void; 126 | /** 127 | * 接口调用失败的回调函数 128 | */ 129 | fail?(err: { error?: number; errorMessage?: string }): void; 130 | /** 131 | * 接口调用结束的回调函数(调用成功、失败都会执行) 132 | */ 133 | complete?( 134 | arg: 135 | | { 136 | /** 137 | * 和被打开页面进行通信 138 | */ 139 | eventChannel: EventChannel; 140 | } 141 | | { 142 | error?: number; 143 | errorMessage?: string; 144 | } 145 | ): void; 146 | }) => Promise<{ 147 | /** 148 | * 和被打开页面进行通信 149 | */ 150 | eventChannel: EventChannel; 151 | }>; 152 | redirectTo: (object: { 153 | /** 154 | * 需要跳转的目标页面路径 155 | * 路径后可以带参数, 目标路径必须为应用内非 tabbar 的,路径与参数之间使用 ?分隔,参数键与参数值用=相连,不同参数必须用&分隔 156 | */ 157 | url: string; 158 | /** 159 | * 接口调用成功的回调函数 160 | */ 161 | success?(data: {}): void; 162 | /** 163 | * 接口调用失败的回调函数 164 | */ 165 | fail?(err: { error?: number; errorMessage?: string }): void; 166 | /** 167 | * 接口调用结束的回调函数(调用成功、失败都会执行) 168 | */ 169 | complete?(arg: { error?: number; errorMessage?: string }): void; 170 | }) => Promise; 171 | navigateBack: (object?: { 172 | /** 173 | * 返回的页面数 174 | * @description 如果 delta 大于现有打开的页面数,则返回到首页 175 | * @default 1 176 | */ 177 | delta?: number | string; 178 | /** 179 | * 接口调用成功的回调函数 180 | */ 181 | success?(data: {}): void; 182 | /** 183 | * 接口调用失败的回调函数 184 | */ 185 | fail?(err: { error?: number; errorMessage?: string }): void; 186 | /** 187 | * 接口调用结束的回调函数(调用成功、失败都会执行) 188 | */ 189 | complete?(arg: { error?: number; errorMessage?: string }): void; 190 | }) => Promise; 191 | switchTab: (object: { 192 | /** 193 | * 跳转的特定 tab 的路径 194 | * @description 目标路径必须为应用内 tabbar 的,且路径后不能带参数 195 | */ 196 | url: string; 197 | /** 198 | * 接口调用成功的回调函数 199 | */ 200 | success?(data: {}): void; 201 | /** 202 | * 接口调用失败的回调函数 203 | */ 204 | fail?(err: { error?: number; errorMessage?: string }): void; 205 | /** 206 | * 接口调用结束的回调函数(调用成功、失败都会执行) 207 | */ 208 | complete?(arg: { error?: number; errorMessage?: string }): void; 209 | }) => Promise; 210 | reLaunch: (object: { 211 | /** 212 | * 需要跳转的目标页面路径 213 | * @description 214 | * 目标路径如果是 Tab 路径后不可以带参数 215 | * 目标路径如果是非 Tab 页,可以携带参数,路径与参数之间使用 `?` 分隔,参数键与参数值用 `=` 相连,不同参数必须用 `&` 分隔 216 | */ 217 | url: string; 218 | /** 219 | * 接口调用成功的回调函数 220 | */ 221 | success?(data: {}): void; 222 | /** 223 | * 接口调用失败的回调函数 224 | */ 225 | fail?(err: { error?: number; errorMessage?: string }): void; 226 | /** 227 | * 接口调用结束的回调函数(调用成功、失败都会执行) 228 | */ 229 | complete?(arg: { error?: number; errorMessage?: string }): void; 230 | }) => Promise; 231 | } 232 | interface IMyNavigateToEvents { 233 | /** 234 | * 特定事件名监听回调 235 | */ 236 | [eventName: string]: (...args: unknown[]) => void; 237 | } 238 | interface EventChannel { 239 | /** 240 | * 在页面间通信中触发一个事件 241 | * @see https://opendocs.alipay.com/mini/api/eventchannel.emit 242 | */ 243 | emit(eventName: string, args?: unknown): void; 244 | /** 245 | * 在页面间通信中停止监听一个事件 246 | * @see https://opendocs.alipay.com/mini/api/eventchannel.off 247 | */ 248 | off(eventName: string, callback: (...args: unknown[]) => void): void; 249 | /** 250 | * 在页面间通信中持续监听一个事件 251 | * @see https://opendocs.alipay.com/mini/api/eventchannel.on 252 | */ 253 | on(eventName: string, callback: (...args: unknown[]) => void): void; 254 | /** 255 | * 在页面间通信中监听一个事件仅一次 256 | * @description 事件触发后失效 257 | * @see https://opendocs.alipay.com/mini/api/eventchannel.once 258 | */ 259 | once(eventName: string, callback: (...args: unknown[]) => void): void; 260 | } 261 | 262 | interface IInstanceSharedMethods { 263 | /** 264 | * 创建 SelectorQuery 对象实例。 265 | * @version 2.7.4 266 | */ 267 | createSelectorQuery(): any; 268 | /** 269 | * 创建 IntersectionObserver 对象实例。 270 | * @version 2.7.4 271 | */ 272 | createIntersectionObserver(): any; 273 | /** 274 | * 创建 MediaQueryObserver 对象实例,用于监听页面 media query 状态的变化。 275 | * @version 2.8.2 276 | * @see https://opendocs.alipay.com/mini/framework/component_object#createMediaQueryObserver 277 | */ 278 | createMediaQueryObserver(): IMediaQueryObserver; 279 | /** 280 | * 获取自定义 tabBar 实例,可以通过判断 `this.getTabBar` 是否为一个函数做兼容性处理 281 | * @version 2.7.20 282 | * @see https://opendocs.alipay.com/mini/framework/page-detail#Page.getTabBar 283 | */ 284 | getTabBar(): T | undefined; 285 | /** 286 | * 查询子组件 287 | * @description 根据传入的 selector 匹配器查询,返回匹配到的第一个组件实例(会被 ref 影响) 288 | * @version 2.8.0 289 | * @see https://opendocs.alipay.com/mini/framework/component_object#%24selectComponent%2F%24selectAllComponents 290 | */ 291 | $selectComponent(selector: string): Component.BaseInstance | void; 292 | /** 293 | * 查询子组件 294 | * @description 根据传入的 selector 匹配器查询,返回匹配到的所有组件实例(会被 ref 影响) 295 | * @version 2.8.0 296 | * @see https://opendocs.alipay.com/mini/framework/component_object#%24selectComponent%2F%24selectAllComponents 297 | */ 298 | $selectAllComponents(selector: string): Component.BaseInstance[]; 299 | /** 300 | * 监听 setData 引发界面更新的开销,参见 获取更新性能统计信息 301 | * @version 2.8.5 302 | * @see https://opendocs.alipay.com/mini/069xfk 303 | */ 304 | setUpdatePerformanceListener( 305 | option: SetUpdatePerformanceListenerOption, 306 | callback?: UpdatePerformanceListener 307 | ): void; 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /packages/my/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/my", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for Alipay's mini program.", 5 | "scripts": {}, 6 | "miniprogram": "./", 7 | "repository": { 8 | "type": "git", 9 | "url": "git@github.com:ant-mini-program/api-typings.git" 10 | }, 11 | "keywords": [ 12 | "tinyapp", 13 | "miniprogram", 14 | "types" 15 | ], 16 | "license": "MIT", 17 | "types": "./types/index.d.ts", 18 | "files": [ 19 | "types" 20 | ], 21 | "publishConfig": { 22 | "registry": "https://registry.npmjs.org/", 23 | "access": "public" 24 | }, 25 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 26 | } 27 | -------------------------------------------------------------------------------- /packages/my/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /packages/my/types/lib.my.extra.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace my { 2 | /** 3 | * @description 通用形式 4 | * @param name JSAPI 名称 5 | * @param opt JSAPI 入参 6 | * @param callback 回调 7 | */ 8 | export function call( 9 | name: string, 10 | opt: any, 11 | callback: (resp: any) => void 12 | ): void; 13 | /** 14 | * @description 无入参形式 15 | * @param name JSAPI 名称 16 | * @param callback 回调 17 | */ 18 | export function call(name: string, callback: (resp: any) => void): void; 19 | /** 20 | * @description 无回调返回 Promise 形式 21 | * @param name JSAPI 名称 22 | * @param opt JSAPI 入参 23 | */ 24 | export function call(name: string, opt?: any): Promise; 25 | 26 | /** 27 | * @param eventName 需要监听的事件名 28 | * @param callback 事件被触发后的回调函数 29 | */ 30 | export function on( 31 | eventName: string, 32 | callback: (...args: any) => any 33 | ): { 34 | /** 35 | * @description 调用该方法后,可移除刚才监听的事件 36 | */ 37 | remove: () => void; 38 | }; 39 | 40 | /** 41 | * @param eventName 需要监听的事件名 42 | * @param callback 事件被触发后的回调函数 43 | */ 44 | export function off(eventName: string, callback: (...args: any) => any): void; 45 | export function canIUse(name: string): boolean; 46 | } 47 | -------------------------------------------------------------------------------- /scripts/set-release-tag.sh: -------------------------------------------------------------------------------- 1 | export V=$(cat lerna.json| jq .version -r) 2 | # 让 latest 都打上 release 的 dist-tag 3 | npx lerna exec --no-bail --no-private --no-sort --stream -- '[ -n $V ] && npm --registry https://registry.npmjs.org/ dist-tag add ${LERNA_PACKAGE_NAME}@$V release' 4 | -------------------------------------------------------------------------------- /tests/global/app.test.ts: -------------------------------------------------------------------------------- 1 | import { expectType } from 'tsd-lite'; 2 | import { IAppOnLaunchOptions } from '../../packages/global/types/lib.global.d'; 3 | 4 | App({ 5 | onLaunch(options: IAppOnLaunchOptions<{ a: string }>) { 6 | console.log('App Launch', options); 7 | expectType(options.path); 8 | expectType(options.query.a); 9 | expectType(options.referrerInfo.appId); 10 | expectType(my.SDKVersion); 11 | }, 12 | onShow() { 13 | console.log('App Show'); 14 | }, 15 | onHide() { 16 | console.log('App Hide'); 17 | }, 18 | globalData: { 19 | hasLogin: false, 20 | }, 21 | }); 22 | -------------------------------------------------------------------------------- /tests/global/component.test.ts: -------------------------------------------------------------------------------- 1 | import { expectType, expectAssignable } from 'tsd-lite'; 2 | 3 | const mixin = Mixin({}); 4 | 5 | Component({ 6 | mixins: [], 7 | test: 111, 8 | data() { 9 | expectAssignable(this); 10 | return { 11 | x: 1, 12 | b: { c: 1 }, 13 | }; 14 | }, 15 | options: { 16 | observers: true, 17 | externalClasses: true, 18 | lifetimes: true, 19 | relations: true, 20 | }, 21 | observers: { 22 | 'field1,field2': function (val1, val2) { 23 | console.log(val1, val2); 24 | }, 25 | '**': function (state) { 26 | console.log(state); 27 | }, 28 | }, 29 | props: { y: 1, b: { c: 1 } }, 30 | onInit() { 31 | expectAssignable(this.is); 32 | expectAssignable(this.$page); 33 | expectAssignable(this.$id); 34 | expectAssignable(this.test); 35 | }, 36 | didMount() { 37 | expectType(this.data.x); 38 | 39 | expectAssignable(this.handleTap); 40 | 41 | expectAssignable(this.setData); 42 | expectAssignable(this.$spliceData); 43 | expectAssignable(this.selectComposedParentComponent); 44 | expectAssignable( 45 | this.selectComposedParentComponent().selectOwnerComponent 46 | ); 47 | expectAssignable(this.selectOwnerComponent); 48 | expectAssignable( 49 | this.selectOwnerComponent().selectComposedParentComponent 50 | ); 51 | expectAssignable(this.getRelationNodes); 52 | 53 | expectAssignable(this.createSelectorQuery); 54 | expectAssignable(this.createIntersectionObserver); 55 | expectAssignable(this.createMediaQueryObserver); 56 | expectAssignable(this.getTabBar); 57 | expectAssignable(this.$selectComponent); 58 | expectAssignable(this.$selectAllComponents); 59 | expectAssignable(this.hasMixin); 60 | expectAssignable(this.setUpdatePerformanceListener); 61 | 62 | expectType<{ x: number; b: { c: number } }>(this.data); 63 | expectType>(this.props); 64 | expectAssignable(this.router.navigateTo); 65 | expectAssignable(this.router.navigateBack); 66 | expectAssignable(this.router.reLaunch); 67 | expectAssignable(this.pageRouter.redirectTo); 68 | expectAssignable(this.pageRouter.switchTab); 69 | }, 70 | didUpdate() {}, 71 | didUnmount() {}, 72 | methods: { 73 | handleTap() { 74 | this.setData({ x: this.data.x + 1 }); 75 | }, 76 | }, 77 | externalClasses: ['am-button'], 78 | lifetimes: { 79 | created() {}, 80 | attached() {}, 81 | ready() {}, 82 | moved() {}, 83 | detached() {}, 84 | }, 85 | relations: { 86 | './ccc': { 87 | type: 'parent', 88 | linked(target) {}, 89 | unlinked(target) {}, 90 | linkChanged(target) {}, 91 | target: mixin, 92 | }, 93 | './ddd': { 94 | type: 'parent', 95 | linked(target) {}, 96 | unlinked(target) {}, 97 | linkChanged(target) {}, 98 | }, 99 | }, 100 | pageEvents: { 101 | onLoad(query) {}, 102 | onShow() {}, 103 | onReady() {}, 104 | onHide() {}, 105 | onUnload() {}, 106 | onBack() {}, 107 | onKeyboardHeight(event) { 108 | expectAssignable(event.height); 109 | }, 110 | onOptionMenuClick() {}, 111 | onPullDownRefresh(event) { 112 | expectAssignable(event.from); 113 | }, 114 | onPageScroll(event) { 115 | expectAssignable(event.scrollHeight); 116 | }, 117 | onTabItemTap(event) { 118 | expectAssignable(event.index); 119 | }, 120 | beforeTabItemTap() {}, 121 | onResize(event) { 122 | expectAssignable(event.size.windowHeight); 123 | expectAssignable(event.size.windowWidth); 124 | }, 125 | onSelectedTabItemTap(event) { 126 | expectAssignable(event.index); 127 | }, 128 | }, 129 | }); 130 | 131 | Component<{}, {}, {}, {}, { test: number }>({ 132 | test: 111, 133 | onInit() { 134 | expectAssignable(this.test); 135 | }, 136 | }); 137 | -------------------------------------------------------------------------------- /tests/global/mixin.test.ts: -------------------------------------------------------------------------------- 1 | import { expectType, expectAssignable } from 'tsd-lite'; 2 | import type { IMixin4Legacy } from '../../packages/alipay'; 3 | const mixin = Mixin({ 4 | data: { 5 | aaa: 1, 6 | }, 7 | didMount() { 8 | expectType(this.data.aaa); 9 | expectAssignable(this.hasMixin); 10 | }, 11 | }); 12 | 13 | // 传统的mixins用法 14 | const mixin4legacy = { 15 | data: { 16 | aaa: 1, 17 | }, 18 | onInit() { 19 | expectType(this.data.aaa); 20 | }, 21 | } as IMixin4Legacy< 22 | { 23 | aaa: number; 24 | }, 25 | {}, 26 | {} 27 | >; 28 | 29 | type ItCanExtractValuesOfTuple = MiniProgram.TExtractValuesOfTuple< 30 | [ 31 | IMixin4Legacy< 32 | { 33 | aaa: number; 34 | }, 35 | {}, 36 | {} 37 | > 38 | ] 39 | >; 40 | 41 | type ItCanExtractDataFromMixin = 42 | MiniProgram.TGetMixinData; 43 | 44 | expectAssignable({ aaa: 1 }); 45 | 46 | Component({ 47 | data: { 48 | b: 1, 49 | }, 50 | // Component的mixins参数即支持传统的直接传入js object 也支持传入 Mixin()实例 51 | mixins: [mixin4legacy, mixin], 52 | didMount() { 53 | expectType(this.data.aaa); 54 | expectType(this.data.b); 55 | }, 56 | }); 57 | 58 | Mixin({ 59 | props: {}, 60 | data: {}, 61 | observers: {}, 62 | onInit() {}, 63 | deriveDataFromProps(nextProps) {}, 64 | didMount() {}, 65 | didUpdate(prevProps, prevData) {}, 66 | didUnmount() {}, 67 | onError() {}, 68 | 69 | // Mixin的mixins参数只支持传入 Mixin()实例 70 | mixins: [mixin], 71 | methods: { 72 | methodFromMixin() {}, 73 | }, 74 | definitionFilter(defFields, definitionFilterArr) {}, 75 | lifetimes: { 76 | created() {}, 77 | attached() {}, 78 | ready() {}, 79 | moved() {}, 80 | detached() {}, 81 | }, 82 | pageEvents: { 83 | onLoad(query) {}, 84 | onKeyboardHeight(event) {}, 85 | onSelectedTabItemTap(event) {}, 86 | }, 87 | relations: { 88 | '.dsd': { 89 | type: 'descendant', 90 | target: mixin, 91 | }, 92 | }, 93 | }); 94 | -------------------------------------------------------------------------------- /tests/global/mixins.test.ts: -------------------------------------------------------------------------------- 1 | import { expectType, expectAssignable } from 'tsd-lite'; 2 | 3 | const mixins1 = { 4 | data: { 5 | b: 1, 6 | }, 7 | } as MiniProgram.Mixin.IMixin4Legacy< 8 | { 9 | b: number; 10 | }, 11 | {}, 12 | {} 13 | >; 14 | 15 | Component({ 16 | mixins: [mixins1, { didMount() {}, methods: { mixinMethod() {} } }], // mixins 方便复用代码 17 | data: { x: 1 }, // 组件内部数据 18 | props: { y: 1 }, // 可给外部传入的属性添加默认值 19 | didMount() { 20 | expectType(this.data.x); 21 | expectAssignable(this.mixinMethod); 22 | expectAssignable(this.data.b); 23 | }, // 生命周期函数 24 | didUpdate() {}, 25 | didUnmount() {}, 26 | methods: { 27 | // 自定义方法 28 | handleTap() { 29 | this.setData({ x: this.data.x + 1 }); // 可使用 setData 改变内部属性 30 | }, 31 | }, 32 | }); 33 | -------------------------------------------------------------------------------- /tests/global/other.test.ts: -------------------------------------------------------------------------------- 1 | import { expectAssignable } from 'tsd-lite'; 2 | 3 | requirePlugin('myPlugin'); 4 | 5 | const result = requirePlugin<{ 6 | foo: string; 7 | }>('tetrisPlugin'); 8 | 9 | expectAssignable(result.foo); 10 | 11 | requirePlugin.async('tetrisPlugin'); 12 | 13 | const result2 = requirePlugin.async<{ 14 | foo: string; 15 | }>('tetrisPlugin'); 16 | 17 | expectAssignable>(result2); 18 | 19 | require('../tetrisPlugin'); 20 | 21 | require<{ 22 | foo: string; 23 | }>('../tetrisPlugin', (result) => { 24 | expectAssignable(result.foo); 25 | }); 26 | 27 | require.async('../tetrisPlugin'); 28 | -------------------------------------------------------------------------------- /tests/global/page.test.ts: -------------------------------------------------------------------------------- 1 | import { expectAssignable } from 'tsd-lite'; 2 | 3 | let basicComponentList = [ 4 | { 5 | type: '基础组件', 6 | list: [], 7 | }, 8 | ]; 9 | 10 | if (my.ap) { 11 | basicComponentList = basicComponentList.concat([ 12 | { 13 | type: '地图', 14 | list: [], 15 | }, 16 | ]); 17 | } 18 | 19 | const extComponentList = [ 20 | { 21 | type: '布局导航', 22 | list: [], 23 | }, 24 | ]; 25 | 26 | const mixin = Mixin({ 27 | pageEvents: { 28 | onLoad() {}, 29 | }, 30 | methods: { 31 | methodFromMixin() {}, 32 | }, 33 | }); 34 | 35 | Page({ 36 | data() { 37 | expectAssignable(this); 38 | return { 39 | top: 0, 40 | hot: [ 41 | { name: 'ScrollView', url: '/page/component/scroll-view/scroll-view' }, 42 | ], 43 | tabs: ['基础组件', '扩展组件'], 44 | activeTab: 0, 45 | basicComponentList, 46 | extComponentList, 47 | titleOpacity: 1, 48 | shadow: false, 49 | }; 50 | }, 51 | options: { 52 | observers: true, 53 | }, 54 | observers: { 55 | 'field1,field2': function (val1, val2) { 56 | console.log(val1, val2); 57 | }, 58 | '**': function (state) { 59 | console.log(state); 60 | }, 61 | }, 62 | mixins: [mixin], 63 | onPageScroll(e) { 64 | expectAssignable(this.setData); 65 | expectAssignable(this.$spliceData); 66 | expectAssignable(this.$batchedUpdates); 67 | expectAssignable(this.createSelectorQuery); 68 | expectAssignable(this.createIntersectionObserver); 69 | expectAssignable(this.createMediaQueryObserver); 70 | expectAssignable(this.getTabBar); 71 | expectAssignable(this.$selectComponent); 72 | expectAssignable(this.$selectAllComponents); 73 | expectAssignable(this.hasMixin); 74 | expectAssignable(this.hasMixin(mixin)); 75 | expectAssignable(this.setUpdatePerformanceListener); 76 | expectAssignable(this.getOpenerEventChannel); 77 | const { scrollTop } = e; 78 | let titleOpacity = 1 - scrollTop * 0.02; 79 | let shadow = false; 80 | 81 | if (titleOpacity < 0) { 82 | titleOpacity = 0; 83 | } 84 | 85 | if (titleOpacity > 1) { 86 | titleOpacity = 1; 87 | } 88 | 89 | if (scrollTop > 80) { 90 | my.setNavigationBar({ 91 | title: '小程序官方示例', 92 | }); 93 | } else { 94 | my.setNavigationBar({ 95 | title: ' ', 96 | }); 97 | } 98 | 99 | if (scrollTop > 320) { 100 | shadow = true; 101 | } else { 102 | shadow = false; 103 | } 104 | 105 | this.setData({ 106 | shadow, 107 | titleOpacity, 108 | }); 109 | }, 110 | onSearchBarTap() { 111 | my.navigateTo({ 112 | url: '/page/common/search/search', 113 | }); 114 | }, 115 | onTabBarTap(e) { 116 | const { index } = e.target.dataset; 117 | this.setData({ 118 | activeTab: index, 119 | }); 120 | }, 121 | onLoad() { 122 | my.getSystemInfo({ 123 | success: (res) => { 124 | if (res.statusBarHeight && res.titleBarHeight) { 125 | this.setData({ 126 | top: res.statusBarHeight + res.titleBarHeight, 127 | }); 128 | } 129 | }, 130 | }); 131 | this.setUpdatePerformanceListener( 132 | { 133 | withDataPaths: true, 134 | }, 135 | (res) => { 136 | expectAssignable(res.dataPaths); 137 | } 138 | ); 139 | }, 140 | goDevCenter() { 141 | my.navigateToMiniProgram({ 142 | appId: '2018082061148052', 143 | path: 'pages/discover/discover', 144 | extraData: { 145 | from: 'miniDemo', 146 | }, 147 | }); 148 | }, 149 | openPage(e) { 150 | my.navigateTo({ 151 | url: e.target.dataset.url, 152 | }); 153 | }, 154 | onShow() { 155 | expectAssignable(this.pageRouter.navigateTo); 156 | expectAssignable(this.pageRouter.navigateBack); 157 | expectAssignable(this.pageRouter.reLaunch); 158 | expectAssignable(this.router.redirectTo); 159 | expectAssignable(this.router.switchTab); 160 | }, 161 | events: { 162 | onLoad(query) {}, 163 | onShow() {}, 164 | onReady() {}, 165 | onHide() {}, 166 | onUnload() {}, 167 | onBack() {}, 168 | onKeyboardHeight(event) { 169 | expectAssignable(event.height); 170 | }, 171 | onOptionMenuClick() {}, 172 | onPullDownRefresh(event) { 173 | expectAssignable(event.from); 174 | }, 175 | onPageScroll(event) { 176 | expectAssignable(event.scrollHeight); 177 | }, 178 | onTabItemTap(event) { 179 | expectAssignable(event.index); 180 | }, 181 | beforeTabItemTap() {}, 182 | onResize(event) { 183 | expectAssignable(event.size.windowHeight); 184 | expectAssignable(event.size.windowWidth); 185 | }, 186 | onSelectedTabItemTap(event) { 187 | expectAssignable(event.index); 188 | }, 189 | }, 190 | }); 191 | -------------------------------------------------------------------------------- /tests/global/this.test.ts: -------------------------------------------------------------------------------- 1 | import { expectType, expectAssignable } from 'tsd-lite'; 2 | 3 | declare global { 4 | interface IGlobalMiniProgramExtraThis4Component { 5 | a: () => {}; 6 | } 7 | } 8 | 9 | Component({ 10 | mixins: [], 11 | data: { x: 1 }, 12 | props: { y: 1 }, 13 | didMount() { 14 | expectType(this.data.x); 15 | expectType(this.props.y); 16 | expectAssignable(this.a); 17 | expectAssignable(this.setData); 18 | }, 19 | }); 20 | -------------------------------------------------------------------------------- /tests/global/worker.test.ts: -------------------------------------------------------------------------------- 1 | import '../../packages/global/types/lib.worker'; 2 | import { expectAssignable } from 'tsd-lite'; 3 | 4 | expectAssignable<(cb: (evt: any) => any) => any>(worker.onMessage); 5 | expectAssignable<(message: any) => any>(worker.postMessage); 6 | expectAssignable<() => any>(worker.testOnProcessKilled); 7 | -------------------------------------------------------------------------------- /tests/my/cloud.test.ts: -------------------------------------------------------------------------------- 1 | import { expectAssignable, expectType } from 'tsd-lite'; 2 | 3 | async function main() { 4 | const c1 = my.cloud.createCloudContext({ 5 | env: 'env-xxx', // 云托管环境 id 6 | }); 7 | // 云托管环境初始化 8 | await c1.init(); 9 | 10 | // 调用云函数 11 | const res = await c1.callFunction({ 12 | name: 'add', 13 | data: { num1: 1, num2: 2 }, 14 | }); 15 | 16 | expectType(res.result); 17 | expectType(res.requestID); 18 | 19 | { 20 | // 调用云存储上传接口 21 | const res = await c1.uploadFile({ 22 | cloudPath: 'example.png', 23 | filePath: 'xxx', 24 | }); 25 | console.log(res); 26 | expectType(res.fileID); 27 | expectType(res.statusCode); 28 | expectType(res.requestID); 29 | } 30 | 31 | { 32 | // 调用云存储下载接口 33 | const res = await c1.downloadFile({ 34 | fileID: 'cloud://env-file/example.png', 35 | }); 36 | expectType(res.tempFilePath); 37 | expectType(res.statusCode); 38 | expectType(res.requestID); 39 | } 40 | 41 | { 42 | // 调用删除云文件接口 43 | const res = await c1.deleteFile({ 44 | fileList: ['cloud://env-xxxx/example.png'], 45 | }); 46 | } 47 | 48 | { 49 | // 获取云文件临时链接 50 | const res = await c1.getTempFileURL({ 51 | fileList: [ 52 | 'cloud://env-xxxx/example1.png', 53 | { fileID: 'cloud://env-xxxx/example2.png', maxAge: 3600 }, 54 | ], 55 | }); 56 | } 57 | 58 | { 59 | // 调用云托管服务 60 | const res = await c1.callContainer({ 61 | path: '/api/count', // 云托管服务路径 62 | method: 'GET', // HTTP 方法 63 | header: { 64 | 'X-Alipay-Service': 'antprod', // 云托管服务名称 65 | }, 66 | }); 67 | } 68 | { 69 | // 获取 Database 实例 70 | // const db = c1.database(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/my/index.test.ts: -------------------------------------------------------------------------------- 1 | import { expectAssignable } from 'tsd-lite'; 2 | 3 | let fs = my.getFileSystemManager(); 4 | my.downloadFile({ 5 | url: 'https://assets.msn.cn/staticsb/statics/latest/widget/LoadingImg.gif', 6 | success(res1: { apFilePath: string; tempFilePath: string }): void { 7 | fs.saveFile({ 8 | tempFilePath: res1.tempFilePath, 9 | filePath: `${my.env.USER_DATA_PATH}/LoadingImg.gif`, 10 | success(res2): void { 11 | expectAssignable(res2.savedFilePath); 12 | console.log(res2); 13 | }, 14 | }); 15 | }, 16 | }); 17 | 18 | let result = fs.accessSync(`${my.env.USER_DATA_PATH}/test.txt`); 19 | console.log(result); 20 | expectAssignable(result.success); 21 | 22 | expectAssignable[0]>({ 23 | mode: 2, 24 | mainTitle: '境内', 25 | mainHeadList: [ 26 | { 27 | title: '定位模块', 28 | type: 1, 29 | list: [], 30 | }, 31 | { 32 | title: '热门城市', 33 | list: [ 34 | { name: '杭州', adCode: '330100' }, 35 | { name: '北京', adCode: '110100' }, 36 | { name: '上海', adCode: '310100' }, 37 | { name: '广州', adCode: '440100' }, 38 | { name: '深圳', adCode: '440300' }, 39 | ], 40 | }, 41 | ], 42 | mainNormalList: [ 43 | { 44 | name: '北京市', 45 | adCode: '110100', 46 | appendName: '北京', 47 | subList: [ 48 | { name: '昌平区', adCode: '110114' }, 49 | { name: '朝阳区', adCode: '110105' }, 50 | { name: '大兴区', adCode: '110115' }, 51 | { name: '东城区', adCode: '110101' }, 52 | { name: '房山区', adCode: '110111' }, 53 | { name: '丰台区', adCode: '110106' }, 54 | { name: '海淀区', adCode: '110108' }, 55 | { name: '怀柔区', adCode: '110116' }, 56 | { name: '门头沟区', adCode: '110109' }, 57 | { name: '密云区', adCode: '110118' }, 58 | { name: '平谷区', adCode: '110117' }, 59 | { name: '石景山区', adCode: '110107' }, 60 | { name: '顺义区', adCode: '110113' }, 61 | { name: '通州区', adCode: '110112' }, 62 | { name: '西城区', adCode: '110102' }, 63 | { name: '延庆区', adCode: '110119' }, 64 | ], 65 | }, 66 | ], 67 | // 境外 68 | seniorTitle: '境外/港澳台', 69 | seniorPageList: [ 70 | { 71 | title: '亚洲', 72 | headList: [ 73 | { 74 | title: '热门城市列表', 75 | list: [{ name: '东京', adCode: '39200037000000000000' }], 76 | }, 77 | ], 78 | normalList: [ 79 | { name: '喀布尔', adCode: '00400003000100000000' }, 80 | { name: '迪拜', adCode: '78400003000300000000' }, 81 | ], 82 | }, 83 | { 84 | title: '大洋洲', 85 | normalList: [ 86 | { name: '堪培拉', adCode: '03600001000100000000' }, 87 | { name: '斐济', adCode: '24200001000100000000' }, 88 | ], 89 | }, 90 | ], 91 | } as Parameters[0]); 92 | 93 | my.chooseDistrict({ 94 | mode: 2, 95 | mainTitle: '境内', 96 | mainHeadList: [ 97 | { 98 | title: '定位模块', 99 | type: 1, 100 | list: [], 101 | }, 102 | { 103 | title: '热门城市', 104 | list: [ 105 | { name: '杭州', adCode: '330100' }, 106 | { name: '北京', adCode: '110100' }, 107 | { name: '上海', adCode: '310100' }, 108 | { name: '广州', adCode: '440100' }, 109 | { name: '深圳', adCode: '440300' }, 110 | ], 111 | }, 112 | ], 113 | mainNormalList: [ 114 | { 115 | name: '北京市', 116 | adCode: '110100', 117 | appendName: '北京', 118 | subList: [ 119 | { name: '昌平区', adCode: '110114' }, 120 | { name: '朝阳区', adCode: '110105' }, 121 | { name: '大兴区', adCode: '110115' }, 122 | { name: '东城区', adCode: '110101' }, 123 | { name: '房山区', adCode: '110111' }, 124 | { name: '丰台区', adCode: '110106' }, 125 | { name: '海淀区', adCode: '110108' }, 126 | { name: '怀柔区', adCode: '110116' }, 127 | { name: '门头沟区', adCode: '110109' }, 128 | { name: '密云区', adCode: '110118' }, 129 | { name: '平谷区', adCode: '110117' }, 130 | { name: '石景山区', adCode: '110107' }, 131 | { name: '顺义区', adCode: '110113' }, 132 | { name: '通州区', adCode: '110112' }, 133 | { name: '西城区', adCode: '110102' }, 134 | { name: '延庆区', adCode: '110119' }, 135 | ], 136 | }, 137 | ], 138 | // 境外 139 | seniorTitle: '境外/港澳台', 140 | seniorPageList: [ 141 | { 142 | title: '亚洲', 143 | headList: [ 144 | { 145 | title: '热门城市列表', 146 | list: [{ name: '东京', adCode: '39200037000000000000' }], 147 | }, 148 | ], 149 | normalList: [ 150 | { name: '喀布尔', adCode: '00400003000100000000' }, 151 | { name: '迪拜', adCode: '78400003000300000000' }, 152 | ], 153 | }, 154 | { 155 | title: '大洋洲', 156 | normalList: [ 157 | { name: '堪培拉', adCode: '03600001000100000000' }, 158 | { name: '斐济', adCode: '24200001000100000000' }, 159 | ], 160 | }, 161 | ], 162 | success: (res) => { 163 | expectAssignable(res.name); 164 | expectAssignable(res.adCode); 165 | }, 166 | }); 167 | 168 | const task = my.connectSocket({ 169 | multiple: true, 170 | url: 'wss://echo.websocket.org', 171 | }); 172 | 173 | expectAssignable(task.close); 174 | expectAssignable(task.offClose); 175 | expectAssignable(task.offError); 176 | expectAssignable(task.offMessage); 177 | expectAssignable(task.offOpen); 178 | expectAssignable(task.onOpen); 179 | expectAssignable(task.onClose); 180 | expectAssignable(task.onError); 181 | expectAssignable(task.onMessage); 182 | expectAssignable(task.send); 183 | 184 | const a = my.connectSocket({ 185 | url: 'wss://echo.websocket.org', 186 | }); 187 | expectAssignable(a); 188 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "typeRoots": ["../packages"], 4 | "experimentalDecorators": true, 5 | "allowJs": true, 6 | "lib": ["ESNEXT", "DOM"], 7 | "esModuleInterop": true, 8 | "skipLibCheck": true, 9 | "module": "CommonJS", 10 | "noImplicitThis": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /widget/alipay/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/alipay-widget", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for Alipay's mini program.", 5 | "scripts": {}, 6 | "repository": { 7 | "type": "git", 8 | "url": "git@github.com:ant-mini-program/api-typings.git" 9 | }, 10 | "keywords": [ 11 | "tinyapp", 12 | "miniprogram", 13 | "types" 14 | ], 15 | "license": "MIT", 16 | "types": "./types/index.d.ts", 17 | "files": [ 18 | "types" 19 | ], 20 | "publishConfig": { 21 | "registry": "https://registry.npmjs.org/", 22 | "access": "public" 23 | }, 24 | "dependencies": { 25 | "@mini-types/global": "3.0.14", 26 | "@mini-types/my-widget": "3.0.14" 27 | }, 28 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 29 | } 30 | -------------------------------------------------------------------------------- /widget/alipay/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | export * from '@mini-types/global/types/lib.global'; 5 | -------------------------------------------------------------------------------- /widget/my/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mini-types/my-widget", 3 | "version": "3.0.14", 4 | "description": "TypeScript declarations for Alipay's mini program.", 5 | "scripts": {}, 6 | "repository": { 7 | "type": "git", 8 | "url": "git@github.com:ant-mini-program/api-typings.git" 9 | }, 10 | "keywords": [ 11 | "tinyapp", 12 | "miniprogram", 13 | "types" 14 | ], 15 | "license": "MIT", 16 | "types": "./types/index.d.ts", 17 | "files": [ 18 | "types" 19 | ], 20 | "publishConfig": { 21 | "registry": "https://registry.npmjs.org/", 22 | "access": "public" 23 | }, 24 | "gitHead": "89563d237a42b6dd1ae44766bd778581430657f6" 25 | } 26 | -------------------------------------------------------------------------------- /widget/my/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /widget/my/types/lib.my.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace my { 2 | /** 3 | * 获取小程序环境变量对象 4 | * @description 相比于 [my.getSystemInfo]() / [my.getSystemInfoSync](), my.env 在使用上开销更低 5 | * @see https://opendocs.alipay.com/mini/api/env 6 | */ 7 | export const env: { 8 | /** 9 | * 文件系统中的用户目录路径 (本地路径) 10 | * @example "https://usr" 11 | */ 12 | USER_DATA_PATH: string; 13 | /** 14 | * 客户端名称简写 15 | * @description 支付宝客户端为 'ap'。 16 | * @example "ap" 17 | */ 18 | clientName: string; 19 | /** 20 | * 客户端版本号 21 | * @example "10.2.90" 22 | */ 23 | clientVersion: string; 24 | /** 25 | * 设置的语言。 26 | * @description 27 | * - 简体中文: "zh-Hans" 28 | * - 英文: "en" 29 | * - 繁体中文-香港: "zh-HK" 30 | * - 繁体中文-台湾: "zh-Hant" 31 | * @example "zh-Hans" 32 | */ 33 | language: string; 34 | /** 35 | * 系统名称 36 | * @description 37 | * - iOS 系统: 'iOS' 38 | * - 安卓系统: 'Android' 39 | * - 其他系统: 'unknown' 40 | * @example "iOS" 41 | */ 42 | platform: string; 43 | /** 44 | * 当前客户端环境 45 | */ 46 | clientEnv?: 'prod' | 'test' | 'stable' | 'pre' | 'unknown'; 47 | }; 48 | /** 49 | * 判断当前是否为 IDE 环境 50 | */ 51 | export const isIDE: boolean; 52 | /** 53 | * 获取基础库版本号 54 | * @description 55 | * 以 `major.minor.patch` 3 段数字作为版本号 56 | * - major: 大版本升级,包含架构升级,可能存在不兼容设计 57 | * - minor: 向前兼容的功能性迭代 58 | * - patch: 向前兼容的小功能及 bug 修复迭代 59 | * @see https://opendocs.alipay.com/mini/api/sdk-version 60 | */ 61 | export const SDKVersion: string; 62 | /** 63 | * 将 ArrayBuffer 转换为 Base64 字符串 64 | * @see https://opendocs.alipay.com/mini/api/021zmz 65 | */ 66 | export function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string; 67 | /** 68 | * 将 Base64 格式字符串转换为 ArrayBuffer 69 | * @see https://opendocs.alipay.com/mini/api/021zmy 70 | */ 71 | export function base64ToArrayBuffer(base64: string): ArrayBuffer; 72 | /** 73 | * 清除本地数据缓存 74 | * @description 75 | * - 清空内嵌 webview 的存储时不会同时清空当前小程序本身的存储数据 76 | * - 支付宝设置中心清除缓存不会导致小程序缓存失效 77 | * @see https://opendocs.alipay.com/mini/api/storage 78 | */ 79 | export function clearStorage(object?: { 80 | /** 81 | * 接口调用成功的回调函数 82 | */ 83 | success?(data: { 84 | /** 85 | * 是否成功 86 | */ 87 | success: boolean; 88 | }): void; 89 | /** 90 | * 接口调用失败的回调函数 91 | */ 92 | fail?(err: { error?: number; errorMessage?: string }): void; 93 | /** 94 | * 接口调用结束的回调函数(调用成功、失败都会执行) 95 | */ 96 | complete?( 97 | arg: 98 | | { 99 | /** 100 | * 是否成功 101 | */ 102 | success: boolean; 103 | } 104 | | { 105 | error?: number; 106 | errorMessage?: string; 107 | } 108 | ): void; 109 | }): Promise<{ 110 | /** 111 | * 是否成功 112 | */ 113 | success: boolean; 114 | }>; 115 | /** 116 | * 同步清除本地数据缓存 117 | * @see https://opendocs.alipay.com/mini/api/ulv85u 118 | */ 119 | export function clearStorageSync(): { 120 | /** 121 | * 是否成功 122 | */ 123 | success: boolean; 124 | }; 125 | /** 126 | * 获取授权码 (AuthCode) 127 | * @see https://opendocs.alipay.com/mini/api/openapi-authorize 128 | */ 129 | export function getAuthCode(object?: { 130 | /** 131 | * 授权类型 132 | * @default auth_base 133 | */ 134 | scopes?: string | string[]; 135 | /** 136 | * 接口调用成功的回调函数 137 | */ 138 | success?(data: { 139 | /** 140 | * 授权码 141 | */ 142 | authCode: string; 143 | /** 144 | * 失败的授权类型 145 | */ 146 | authErrorScopes: IMyApGetAuthCodeAuthErrorScopes; 147 | /** 148 | * 成功的授权 scope 149 | */ 150 | authSuccessScopes: ( 151 | | 'auth_base' 152 | | 'auth_user' 153 | | 'auth_zhima' 154 | | 'order_service' 155 | | 'trip_ticket' 156 | | 'ride_hailing' 157 | | 'charging_pile' 158 | | 'ptjob_order_sync' 159 | | 'indr_order_sync' 160 | | 'car_rental_auth' 161 | | 'hospital_order' 162 | | 'consumer_finance' 163 | )[]; 164 | }): void; 165 | /** 166 | * 接口调用失败的回调函数 167 | */ 168 | fail?(err: { error?: number; errorMessage?: string }): void; 169 | /** 170 | * 接口调用结束的回调函数(调用成功、失败都会执行) 171 | */ 172 | complete?( 173 | arg: 174 | | { 175 | /** 176 | * 授权码 177 | */ 178 | authCode: string; 179 | /** 180 | * 失败的授权类型 181 | */ 182 | authErrorScopes: IMyApGetAuthCodeAuthErrorScopes; 183 | /** 184 | * 成功的授权 scope 185 | */ 186 | authSuccessScopes: ( 187 | | 'auth_base' 188 | | 'auth_user' 189 | | 'auth_zhima' 190 | | 'order_service' 191 | | 'trip_ticket' 192 | | 'ride_hailing' 193 | | 'charging_pile' 194 | | 'ptjob_order_sync' 195 | | 'indr_order_sync' 196 | | 'car_rental_auth' 197 | | 'hospital_order' 198 | | 'consumer_finance' 199 | )[]; 200 | } 201 | | { 202 | error?: number; 203 | errorMessage?: string; 204 | } 205 | ): void; 206 | }): Promise<{ 207 | /** 208 | * 授权码 209 | */ 210 | authCode: string; 211 | /** 212 | * 失败的授权类型 213 | */ 214 | authErrorScopes: IMyApGetAuthCodeAuthErrorScopes; 215 | /** 216 | * 成功的授权 scope 217 | */ 218 | authSuccessScopes: ( 219 | | 'auth_base' 220 | | 'auth_user' 221 | | 'auth_zhima' 222 | | 'order_service' 223 | | 'trip_ticket' 224 | | 'ride_hailing' 225 | | 'charging_pile' 226 | | 'ptjob_order_sync' 227 | | 'indr_order_sync' 228 | | 'car_rental_auth' 229 | | 'hospital_order' 230 | | 'consumer_finance' 231 | )[]; 232 | }>; 233 | /** 234 | * 获取缓存数据的异步接口 235 | * @see https://opendocs.alipay.com/mini/api/azfobl 236 | */ 237 | export function getStorage(object: { 238 | /** 239 | * 本地缓存中指定的 key 240 | */ 241 | key: string; 242 | /** 243 | * 接口调用成功的回调函数 244 | */ 245 | success?(data: { 246 | /** 247 | * key 对应的内容 248 | */ 249 | data: any; 250 | }): void; 251 | /** 252 | * 接口调用失败的回调函数 253 | */ 254 | fail?(err: { error?: number; errorMessage?: string }): void; 255 | /** 256 | * 接口调用结束的回调函数(调用成功、失败都会执行) 257 | */ 258 | complete?( 259 | arg: 260 | | { 261 | /** 262 | * key 对应的内容 263 | */ 264 | data: any; 265 | } 266 | | { 267 | error?: number; 268 | errorMessage?: string; 269 | } 270 | ): void; 271 | }): Promise<{ 272 | /** 273 | * key 对应的内容 274 | */ 275 | data: any; 276 | }>; 277 | /** 278 | * 获取缓存数据相关信息 279 | * @see https://opendocs.alipay.com/mini/api/zvmanq 280 | */ 281 | export function getStorageInfo(object?: { 282 | /** 283 | * 接口调用成功的回调函数 284 | */ 285 | success?(data: { 286 | /** 287 | * 当前 storage 中所有的 key 288 | */ 289 | keys: string[]; 290 | /** 291 | * 当前占用的空间大小,单位为 KB 292 | */ 293 | currentSize: number; 294 | /** 295 | * 限制的空间大小,单位为 KB 296 | */ 297 | limitSize: number; 298 | }): void; 299 | /** 300 | * 接口调用失败的回调函数 301 | */ 302 | fail?(err: { error?: number; errorMessage?: string }): void; 303 | /** 304 | * 接口调用结束的回调函数(调用成功、失败都会执行) 305 | */ 306 | complete?( 307 | arg: 308 | | { 309 | /** 310 | * 当前 storage 中所有的 key 311 | */ 312 | keys: string[]; 313 | /** 314 | * 当前占用的空间大小,单位为 KB 315 | */ 316 | currentSize: number; 317 | /** 318 | * 限制的空间大小,单位为 KB 319 | */ 320 | limitSize: number; 321 | } 322 | | { 323 | error?: number; 324 | errorMessage?: string; 325 | } 326 | ): void; 327 | }): Promise<{ 328 | /** 329 | * 当前 storage 中所有的 key 330 | */ 331 | keys: string[]; 332 | /** 333 | * 当前占用的空间大小,单位为 KB 334 | */ 335 | currentSize: number; 336 | /** 337 | * 限制的空间大小,单位为 KB 338 | */ 339 | limitSize: number; 340 | }>; 341 | /** 342 | * 同步获取缓存数据相关信息 343 | * @see https://opendocs.alipay.com/mini/api/uw5rdl 344 | */ 345 | export function getStorageInfoSync(): { 346 | /** 347 | * 当前 storage 中所有的 key 348 | */ 349 | keys: string[]; 350 | /** 351 | * 当前占用的空间大小,单位为 KB 352 | */ 353 | currentSize: number; 354 | /** 355 | * 限制的空间大小,单位为 KB 356 | */ 357 | limitSize: number; 358 | }; 359 | /** 360 | * 同步获取缓存数据 361 | * @see https://opendocs.alipay.com/mini/api/ox0wna 362 | */ 363 | export function getStorageSync(object: { 364 | /** 365 | * 本地缓存中指定的 key 366 | */ 367 | key: string; 368 | }): { 369 | /** 370 | * key 对应的内容 371 | */ 372 | data: unknown; 373 | }; 374 | /** 375 | * 获取手机系统信息 376 | * @see https://opendocs.alipay.com/mini/api/system-info 377 | */ 378 | export function getSystemInfo(object?: { 379 | /** 380 | * 额外返回 `notification*Authorized` 相关字段 381 | */ 382 | includeNotification?: boolean; 383 | /** 384 | * 额外返回 `bluetooth*`相关字段 385 | */ 386 | includeBluetooth?: boolean; 387 | /** 388 | * 接口调用成功的回调函数 389 | */ 390 | success?(data: ITypeSystemInfo): void; 391 | /** 392 | * 接口调用失败的回调函数 393 | */ 394 | fail?(err: { error?: number; errorMessage?: string }): void; 395 | /** 396 | * 接口调用结束的回调函数(调用成功、失败都会执行) 397 | */ 398 | complete?( 399 | arg: 400 | | ITypeSystemInfo 401 | | { 402 | error?: number; 403 | errorMessage?: string; 404 | } 405 | ): void; 406 | }): Promise; 407 | /** 408 | * 获取手机系统信息的同步接口 409 | * @see https://opendocs.alipay.com/mini/api/gawhvz 410 | */ 411 | export function getSystemInfoSync(object?: { 412 | /** 413 | * 额外返回 `notification*Authorized` 相关字段 414 | */ 415 | includeNotification?: boolean; 416 | /** 417 | * 额外返回 bluetooth*相关字段 418 | */ 419 | includeBluetooth?: boolean; 420 | }): ITypeSystemInfo; 421 | /** 422 | * 跳转到其他小程序 423 | * @see https://opendocs.alipay.com/mini/api/yz6gnx 424 | */ 425 | export function navigateToMiniProgram(object: { 426 | /** 427 | * 要跳转的目标小程序appId。 428 | */ 429 | appId: string; 430 | /** 431 | * 打开的页面路径,如果为空则打开首页。 432 | */ 433 | path?: string; 434 | /** 435 | * 用于设置目标小程序应用的 `query` 数据。目标小程序可在 [App.onLaunch](GlobalThis.App) (冷启动)或 [App.onshow](GlobalThis.App) (热启动)中通过 `options.query` 获取 436 | * @description 目标小程序可在 App.onLaunch(),App.onShow() 中的 query 字段获取到这份数据。 437 | */ 438 | query?: IMyNavigateToMiniProgramQuery; 439 | /** 440 | * 需要传递给目标小程序的数据。目标小程序可在 [App.onLaunch](GlobalThis.App) (冷启动)或 [App.onshow](GlobalThis.App) (热启动)中通过 `options.referrerInfo.extraData` 获取 441 | * @description 目标小程序可在 App.onLaunch(),App.onShow() 中的 referrerInfo.extraData 字段获取到这份数据。 442 | */ 443 | extraData?: IMyNavigateToMiniProgramExtraData; 444 | /** 445 | * 指定需要打开的小程序的版本类型 446 | * @description 仅在当前小程序为开发版或体验版时此参数有效;如果当前小程序是正式版,则打开的小程序必定是正式版。 447 | * @default "release" 448 | */ 449 | envVersion?: 'develop' | 'trial' | 'release'; 450 | /** 451 | * 接口调用成功的回调函数 452 | */ 453 | success?(data: {}): void; 454 | /** 455 | * 接口调用失败的回调函数 456 | */ 457 | fail?(err: { error?: number; errorMessage?: string }): void; 458 | /** 459 | * 接口调用结束的回调函数(调用成功、失败都会执行) 460 | */ 461 | complete?(arg: { error?: number; errorMessage?: string }): void; 462 | }): Promise; 463 | /** 464 | * 取消监听小程序错误事件 465 | * @see https://opendocs.alipay.com/mini/00njqm 466 | */ 467 | export function offError(cb?: (message: string, stack: string) => void): void; 468 | /** 469 | * 取消监听未处理的 Promise 拒绝事件 470 | * @see https://opendocs.alipay.com/mini/00nfnd 471 | */ 472 | export function offUnhandledRejection( 473 | cb?: (param: { 474 | /** 475 | * reject() 的接收值,一般是 error 对象 476 | */ 477 | reason: Error | unknown; 478 | /** 479 | * 被 reject 的 Promise 对象 480 | */ 481 | promise: Promise; 482 | }) => void 483 | ): void; 484 | /** 485 | * 监听小程序错误事件 486 | * @description 487 | * 目前仅指 JS 执行错误。触发时机和参数与 App.onError 的一致。 488 | * 使用 my.onError 监听到的报错,app.js 中的 onError 方法也会监听到。 489 | * 使用 my.onError 监听页面报错,如果在多个页面开启监听没有关闭,则页面报错时会触发多个监听事件,建议在页面关闭时调用 my.offError 关闭监听。 490 | * @see https://opendocs.alipay.com/mini/00nnsx 491 | */ 492 | export function onError(cb: (message: string, stack: string) => void): void; 493 | /** 494 | * 监听未处理的 Promise 拒绝事件 495 | * @description 当 Promise 被 reject 且没有 reject 处理器的时候,会触发 unhandledrejection 事件,该事件的回调时机和参数与 App.onUnhandledRejection 的一致。 496 | * @see https://opendocs.alipay.com/mini/00nd0f 497 | */ 498 | export function onUnhandledRejection( 499 | cb: (param: { 500 | /** 501 | * reject() 的接收值,一般是 error 对象 502 | */ 503 | reason: Error | unknown; 504 | /** 505 | * 被 reject 的 Promise 对象 506 | */ 507 | promise: Promise; 508 | }) => void 509 | ): void; 510 | /** 511 | * 删除缓存数据 512 | * @see https://opendocs.alipay.com/mini/api/of9hze 513 | */ 514 | export function removeStorage(object: { 515 | /** 516 | * 缓存数据的 key 517 | */ 518 | key: string; 519 | /** 520 | * 接口调用成功的回调函数 521 | */ 522 | success?(data: { 523 | /** 524 | * 是否成功 525 | */ 526 | success: true; 527 | }): void; 528 | /** 529 | * 接口调用失败的回调函数 530 | */ 531 | fail?(err: { error?: number; errorMessage?: string }): void; 532 | /** 533 | * 接口调用结束的回调函数(调用成功、失败都会执行) 534 | */ 535 | complete?( 536 | arg: 537 | | { 538 | /** 539 | * 是否成功 540 | */ 541 | success: true; 542 | } 543 | | { 544 | error?: number; 545 | errorMessage?: string; 546 | } 547 | ): void; 548 | }): Promise<{ 549 | /** 550 | * 是否成功 551 | */ 552 | success: true; 553 | }>; 554 | /** 555 | * 同步删除缓存数据 556 | * @see https://opendocs.alipay.com/mini/api/ytfrk4 557 | */ 558 | export function removeStorageSync(object: { 559 | /** 560 | * 缓存数据的 key 561 | */ 562 | key: string; 563 | }): { 564 | /** 565 | * 是否成功 566 | */ 567 | success: true; 568 | }; 569 | /** 570 | * 发起网络请求 571 | * @description [my.httpRequest]() 已不再维护,建议使用 [my.request]() 572 | * @see https://opendocs.alipay.com/mini/api/owycmh 573 | */ 574 | export function request(object: { 575 | /** 576 | * 目标服务器 URL 577 | * @description 578 | * - 目前只支持 HTTPS 协议的请求 579 | * - 目前只支持与 *域名白名单* 中的域名通讯 580 | * - 开发过程中,可通过开发者工具 **详情 > 域名信息 > 忽略 httpRequest 域名合法性检查** 忽略该限制(模拟器、预览以及真机调试场景不会校验域名合法性) 581 | * - 正式/体验版本必须在 **支付宝小程序管理中心 > 小程序详情 > 设置 > 开发设置 > 服务器域名白名单** 中配置 582 | * - 域名添加或删除后仅对新版本生效,老版本仍使用修改前的域名配置 583 | */ 584 | url: string; 585 | /** 586 | * 返回的数据格式 587 | * @default 'json' 588 | */ 589 | dataType?: 'json' | 'text' | 'base64' | 'arraybuffer'; 590 | /** 591 | * HTTP 请求方法 592 | * @default 'GET' 593 | */ 594 | method?: 595 | | 'GET' 596 | | 'POST' 597 | | 'PUT' 598 | | 'DELETE' 599 | | 'OPTIONS' 600 | | 'HEAD' 601 | | 'TRACE' 602 | | 'CONNECT'; 603 | /** 604 | * 传给服务器的数据 605 | * @description 606 | * 传给服务器的数据最终会是 string 类型,如果 data 不是 string 类型,会被转换成 string 。转换规则如下: 607 | * - 若方法为 `GET`,会将数据转换成 querystring 形式: `encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...` 608 | * - 若方法为 `POST` 且 `headers['content-type']` 为 `application/json` ,会对数据进行 JSON 序列化。 609 | * - 若方法为 `POST` 且 `headers['content-type']` 为 `application/x-www-form-urlencoded` ,会将数据转换成 querystring形式: `encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...` 610 | */ 611 | data?: string | Record | ArrayBuffer; 612 | /** 613 | * 设置请求的 HTTP 头对象 614 | * @description 615 | * - "content-type" 字段默认为 `application/json` 616 | * - `referer` 字段不可设置,其格式固定为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page},其中 {appid} 为小程序的 APPID,{version} 为小程序发布标识,{page} 为小程序当前页面。 617 | */ 618 | headers?: Record; 619 | /** 620 | * 设置请求的 HTTP 头对象 621 | * @description 622 | * - "content-type" 字段默认为 `application/json` 623 | * - `referer` 字段不可设置,其格式固定为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page},其中 {appid} 为小程序的 APPID,{version} 为小程序发布标识,{page} 为小程序当前页面。 624 | */ 625 | header?: Record; 626 | /** 627 | * 超时时间,单位 ms 628 | * @default 30000 629 | */ 630 | timeout?: number; 631 | /** 632 | * referer 策略 633 | * @default 'querystring' 634 | */ 635 | referrerStrategy?: string; 636 | /** 637 | * 接口调用成功的回调函数 638 | */ 639 | success?(data: { 640 | /** 641 | * 响应数据,格式取决于请求时的 `dataType` 参数 642 | */ 643 | data: string | Record | ArrayBuffer; 644 | /** 645 | * HTTP 响应码。 646 | */ 647 | status: number; 648 | /** 649 | * HTTP 响应头。 650 | */ 651 | headers: Record; 652 | /** 653 | * HTTP 响应码。 654 | */ 655 | statusCode: number; 656 | /** 657 | * HTTP 响应头。 658 | */ 659 | header: Record; 660 | }): void; 661 | /** 662 | * 接口调用失败的回调函数 663 | */ 664 | fail?( 665 | err: 666 | | { 667 | error?: number; 668 | errorMessage?: string; 669 | } 670 | | { 671 | error: 19; 672 | errorMessage: 'http status error'; 673 | } 674 | | { 675 | error: 14; 676 | errorMessage: 'parse arraybuffer data error'; 677 | } 678 | | { 679 | error: 14; 680 | errorMessage: 'JSON parse data error'; 681 | } 682 | ): void; 683 | /** 684 | * 接口调用结束的回调函数(调用成功、失败都会执行) 685 | */ 686 | complete?( 687 | arg: 688 | | { 689 | /** 690 | * 响应数据,格式取决于请求时的 `dataType` 参数 691 | */ 692 | data: string | Record | ArrayBuffer; 693 | /** 694 | * HTTP 响应码。 695 | */ 696 | status: number; 697 | /** 698 | * HTTP 响应头。 699 | */ 700 | headers: Record; 701 | /** 702 | * HTTP 响应码。 703 | */ 704 | statusCode: number; 705 | /** 706 | * HTTP 响应头。 707 | */ 708 | header: Record; 709 | } 710 | | ( 711 | | { 712 | error?: number; 713 | errorMessage?: string; 714 | } 715 | | { 716 | error: 19; 717 | errorMessage: 'http status error'; 718 | } 719 | | { 720 | error: 14; 721 | errorMessage: 'parse arraybuffer data error'; 722 | } 723 | | { 724 | error: 14; 725 | errorMessage: 'JSON parse data error'; 726 | } 727 | ) 728 | ): void; 729 | }): Promise<{ 730 | /** 731 | * 响应数据,格式取决于请求时的 `dataType` 参数 732 | */ 733 | data: string | Record | ArrayBuffer; 734 | /** 735 | * HTTP 响应码。 736 | */ 737 | status: number; 738 | /** 739 | * HTTP 响应头。 740 | */ 741 | headers: Record; 742 | /** 743 | * HTTP 响应码。 744 | */ 745 | statusCode: number; 746 | /** 747 | * HTTP 响应头。 748 | */ 749 | header: Record; 750 | }> & 751 | RequestTask; 752 | /** 753 | * 将数据存储在本地缓存的指定的 key 中 754 | * @see https://opendocs.alipay.com/mini/api/eocm6v 755 | */ 756 | export function setStorage(object: { 757 | /** 758 | * 存储的数据 759 | * @description 760 | * - 单个 key 允许存储的最大数据大小为 200KB 761 | * - 所有数据存储上限为 10MB。 762 | */ 763 | data: unknown; 764 | /** 765 | * 存储的 key 766 | */ 767 | key: string; 768 | /** 769 | * 接口调用成功的回调函数 770 | */ 771 | success?(data: {}): void; 772 | /** 773 | * 接口调用失败的回调函数 774 | */ 775 | fail?(err: { error?: number; errorMessage?: string }): void; 776 | /** 777 | * 接口调用结束的回调函数(调用成功、失败都会执行) 778 | */ 779 | complete?(arg: { error?: number; errorMessage?: string }): void; 780 | }): Promise; 781 | /** 782 | * 同步将数据存储在本地缓存的指定的 key 中 783 | * @see https://opendocs.alipay.com/mini/api/cog0du 784 | */ 785 | export function setStorageSync(object: { 786 | /** 787 | * 需要存储的内容 788 | */ 789 | data: unknown; 790 | /** 791 | * 本地缓存中指定的 key 792 | */ 793 | key: string; 794 | }): void; 795 | export interface RequestTask { 796 | /** 797 | * 取消本次任务 798 | * @see https://opendocs.alipay.com/mini/075h2u 799 | */ 800 | abort(object: { 801 | requestTaskId: number; 802 | operationType: 'abort'; 803 | /** 804 | * 接口调用成功的回调函数 805 | */ 806 | success?(data: { success: true }): void; 807 | /** 808 | * 接口调用失败的回调函数 809 | */ 810 | fail?(err: { error?: number; errorMessage?: string }): void; 811 | /** 812 | * 接口调用结束的回调函数(调用成功、失败都会执行) 813 | */ 814 | complete?( 815 | arg: 816 | | { 817 | success: true; 818 | } 819 | | { 820 | error?: number; 821 | errorMessage?: string; 822 | } 823 | ): void; 824 | }): Promise<{ 825 | success: true; 826 | }>; 827 | /** 828 | * 移除 HTTP Response Header 事件的监听函数 829 | * @see https://opendocs.alipay.com/mini/075qu0 830 | */ 831 | offHeadersReceived(cb?: (arg: {}) => void): void; 832 | /** 833 | * 监听 HTTP Response Header 事件。会比请求完成事件更早 834 | * @see https://opendocs.alipay.com/mini/075pji 835 | */ 836 | onHeadersReceived( 837 | cb: (arg: { 838 | /** 839 | * 开发者服务器返回的 HTTP Response Header 840 | */ 841 | headers: IRequestTaskOnHeadersReceivedHeaders; 842 | }) => void 843 | ): void; 844 | } 845 | interface IMyApGetAuthCodeAuthErrorScopes { 846 | /** 847 | * key 是授权失败的 scope,value 是对应的错误码 848 | */ 849 | [scope: string]: string; 850 | } 851 | interface IMyNavigateToMiniProgramExtraData { 852 | /** 853 | * 参数键值对 854 | */ 855 | [key: string]: unknown; 856 | } 857 | interface IMyNavigateToMiniProgramQuery { 858 | /** 859 | * query 参数键值对 860 | */ 861 | [key: string]: unknown; 862 | } 863 | interface IRequestTaskOnHeadersReceivedHeaders { 864 | [key: string]: string; 865 | } 866 | interface ITypeSystemInfo { 867 | /** 868 | * 当前运行的客户端 869 | * @example "alipay" 870 | */ 871 | app: string; 872 | /** 873 | * 客户端设置的语言 874 | * @example "zh-Hans" 875 | */ 876 | language: string; 877 | /** 878 | * 设备像素比 879 | * @example 3 880 | */ 881 | pixelRatio: number; 882 | /** 883 | * 平台 884 | * @example "Android" 885 | */ 886 | platform: string; 887 | /** 888 | * @deprecated 已废弃,不要使用 889 | * 平台类型 890 | * @example "ap" 891 | */ 892 | platformType?: string; 893 | /** 894 | * 屏幕宽度 895 | * @example 1080 896 | */ 897 | screenWidth: number; 898 | /** 899 | * 标题栏高度 900 | * @example 48 901 | */ 902 | titleBarHeight: number; 903 | /** 904 | * 客户端版本号 905 | * @example "10.2.28.1769" 906 | */ 907 | version: string; 908 | /** 909 | * 窗口宽度 910 | * @example 360 911 | */ 912 | windowWidth: number; 913 | /** 914 | * 用于 Android API 版本 915 | * @example 29 916 | */ 917 | apiLevel?: number; 918 | /** 919 | * 用来区分显示企业商家服务/个人等界面信息 920 | * @example "normal" 921 | */ 922 | appMode?: `${ESystemInfoAppMode}`; 923 | /** 924 | * 手机品牌 925 | * @example "HUAWEI" 926 | */ 927 | brand: string; 928 | /** 929 | * 当前电池电量 930 | * @example "79%" 931 | */ 932 | currentBattery: string; 933 | /** 934 | * 用户设置字体大小 935 | * @example 1 936 | */ 937 | fontSizeSetting: number; 938 | /** 939 | * 手机型号 940 | * @example "HUAWEI TAS-AL00" 941 | */ 942 | model: string; 943 | /** 944 | * 设备性能分级 945 | */ 946 | performance: `${ETypeSystemInfo$Performance}`; 947 | /** 948 | * 屏幕信息 949 | */ 950 | screen: ITypeSystemInfo$Screen; 951 | /** 952 | * 屏幕高度 953 | * @example 2259 954 | */ 955 | screenHeight: number; 956 | /** 957 | * 状态栏高度 958 | * @example 27 959 | */ 960 | statusBarHeight: number; 961 | /** 962 | * 设备磁盘容量 963 | * @example "118 GB" 964 | */ 965 | storage: string; 966 | /** 967 | * 系统版本 968 | * @example "10" 969 | */ 970 | system: string; 971 | /** 972 | * 透明状态栏 973 | * @example false 974 | */ 975 | transparentTitle: boolean; 976 | /** 977 | * 窗口高度 978 | * @example 780 979 | */ 980 | windowHeight: number; 981 | /** 982 | * 是否 iphoneX 系列 983 | * @example false 984 | */ 985 | isIphoneXSeries: boolean; 986 | /** 987 | * 在竖屏正方向下的安全区域 988 | */ 989 | safeArea?: ITypeSystemInfo$SafeArea; 990 | /** 991 | * 允许支付宝使用相册的开关 992 | */ 993 | albumAuthorized: boolean; 994 | /** 995 | * 允许支付宝使用摄像头的开关 996 | */ 997 | cameraAuthorized: boolean; 998 | /** 999 | * 允许支付宝使用定位的开关 1000 | */ 1001 | locationAuthorized: boolean; 1002 | /** 1003 | * 允许支付宝使用麦克风的开关 1004 | */ 1005 | microphoneAuthorized: boolean; 1006 | /** 1007 | * 定位的系统开关 1008 | */ 1009 | locationEnabled: boolean; 1010 | /** 1011 | * Wi-Fi 的系统开关 1012 | */ 1013 | wifiEnabled: boolean; 1014 | /** 1015 | * 蓝牙的系统开关 1016 | */ 1017 | bluetoothEnabled: boolean; 1018 | /** 1019 | * 允许支付宝使用蓝牙的开关 1020 | */ 1021 | bluetoothAuthorized: boolean; 1022 | /** 1023 | * 允许支付宝通知的开关 1024 | */ 1025 | notificationAuthorized: boolean; 1026 | /** 1027 | * 允许支付宝通知带有提醒的开关 1028 | */ 1029 | notificationAlertAuthorized: boolean; 1030 | /** 1031 | * 允许支付宝通知带有标记的开关 1032 | */ 1033 | notificationBadgeAuthorized: boolean; 1034 | /** 1035 | * 允许支付宝通知带有声音的开关 1036 | */ 1037 | notificationSoundAuthorized: boolean; 1038 | /** 1039 | * 悬浮窗权限 1040 | */ 1041 | overlayAuthorized: boolean; 1042 | } 1043 | interface ITypeSystemInfo$SafeArea { 1044 | left: number; 1045 | right: number; 1046 | top: number; 1047 | bottom: number; 1048 | width: number; 1049 | height: number; 1050 | } 1051 | interface ITypeSystemInfo$Screen { 1052 | /** 1053 | * 屏幕宽度 1054 | */ 1055 | width: number; 1056 | /** 1057 | * 屏幕高度 1058 | */ 1059 | height: number; 1060 | } 1061 | } 1062 | 1063 | declare const enum ESystemInfoAppMode { 1064 | /** 1065 | * 标准版 1066 | */ 1067 | normal = 'normal', 1068 | /** 1069 | * 大字体版 1070 | */ 1071 | bigFontSize = 'bigFontSize', 1072 | /** 1073 | * 国际版 1074 | */ 1075 | INT = 'INT', 1076 | /** 1077 | * 澳门版 1078 | */ 1079 | MO = 'MO', 1080 | /** 1081 | * 企业版 1082 | */ 1083 | Enterprise = 'Enterprise', 1084 | /** 1085 | * 青少年版 1086 | */ 1087 | teenager = 'teenager', 1088 | } 1089 | 1090 | declare const enum ETypeSystemInfo$Performance { 1091 | /** 1092 | * 高性能 1093 | * @description 1094 | * - iOS 设备运行内存大于等于 4GB (对应 iPhone Xs 及以上) 1095 | * - Android 设备运行内存大于等于 4GB 1096 | */ 1097 | high = 'high', 1098 | /** 1099 | * 性能中等 1100 | * @description 1101 | * - iOS 设备运行内存大于等于 2GB (对应 iPhone 6s ~ iPhone XR) 1102 | * - Android 设备运行内存大于等于 3GB 且 CPU 核心数大于 4 1103 | */ 1104 | middle = 'middle', 1105 | /** 1106 | * 性能较弱 1107 | */ 1108 | low = 'low', 1109 | /** 1110 | * 无法识别 1111 | * @description 设备运行内存无法识别 1112 | */ 1113 | unknown = 'unknown', 1114 | } 1115 | -------------------------------------------------------------------------------- /widget/my/types/lib.my.extra.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace my { 2 | /** 3 | * @description 通用形式 4 | * @param name JSAPI 名称 5 | * @param opt JSAPI 入参 6 | * @param callback 回调 7 | */ 8 | export function call( 9 | name: string, 10 | opt: any, 11 | callback: (resp: any) => void 12 | ): void; 13 | /** 14 | * @description 无入参形式 15 | * @param name JSAPI 名称 16 | * @param callback 回调 17 | */ 18 | export function call(name: string, callback: (resp: any) => void): void; 19 | /** 20 | * @description 无回调返回 Promise 形式 21 | * @param name JSAPI 名称 22 | * @param opt JSAPI 入参 23 | */ 24 | export function call(name: string, opt?: any): Promise; 25 | 26 | /** 27 | * @param eventName 需要监听的事件名 28 | * @param callback 事件被触发后的回调函数 29 | */ 30 | export function on( 31 | eventName: string, 32 | callback: (...args: any) => any 33 | ): { 34 | /** 35 | * @description 调用该方法后,可移除刚才监听的事件 36 | */ 37 | remove: () => void; 38 | }; 39 | 40 | /** 41 | * @param eventName 需要监听的事件名 42 | * @param callback 事件被触发后的回调函数 43 | */ 44 | export function off(eventName: string, callback: (...args: any) => any): void; 45 | export function canIUse(name: string): boolean; 46 | } 47 | --------------------------------------------------------------------------------