Create a project Create a project in WeChat Developer Tools and select Renovation Project Edit the { "name": "miniprogram-ts-quickstart", "version": "1.0.0", "description": "", "scripts": { "compile": "./node_modules/typescript/bin/tsc", "tsc": "node ./node_modules/typescript/lib/tsc.js" }, "keywords": [], "author": "", "license": "", "dependencies": { }, "devDependencies": { "typescript": "^4.1.3", "miniprogram-api-typings": "^2.12.1-beta.0" } } Edit the tsconfig.json file, change lib to ["esnext"], support the latest syntax, and delete the typeRoots configuration item { "compilerOptions": { "strictNullChecks": true, "noImplicitAny": true, "module": "CommonJS", "target": "ES5", "allowJs": false, "experimentalDecorators": true, "noImplicitThis": true, "noImplicitReturns": true, "alwaysStrict": true, "inlineSourceMap": true, "inlineSources": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "strict": true, "removeComments": true, "pretty": true, "strictPropertyInitialization": true, "lib": ["esnext"] }, "include": [ "./**/*.ts" ], "exclude": [ "node_modules" ] } Execute Delete the typings directory under the project, and copy the types file of miniprogram-api-typings under node_modules to the project root directory Create an interface directory under miniprogram and create an IAppOption.ts file, and finally edit the app.ts file. // IAppOption.ts export default interface IAppOption { globalData: { text: string; } } // app.ts import IAppOption from "./interface/IAppOption"; App<IAppOption>({ globalData: { text: "Hello, Word!" }, onLaunch() { } }) In Details -> Local Settings -> Debug Base Library, directly select the latest Using Promise WeChat Mini Program API Previously, you could use Now you can use it directly, such as wx.getStorageInfo, which returns getStorageInfo<TOption extends GetStorageInfoOption>( option?: TOption ): PromisifySuccessResult<TOption, GetStorageInfoOption> type PromisifySuccessResult< P, T extends AsyncMethodOptionLike > = P extends { success: any } ? void : P extends { fail: any } ? void : P extends { complete: any } ? void : Promise<Parameters<Exclude<T['success'], undefined>>[0]> Two usages, most APIs support wx.getStorageInfo({ success: () => { console.log('Successful execution') }, fail: () => { console.log('Failed to execute') }, complete: () => { console.log('Interface call ends') } }) wx.getStorageInfo().then(() => { console.log('Successful execution') }).catch(() => { console.log('Failed to execute') }).finally(() => { console.log('Interface call ends') }) Source code: https://github.com/NikolasSky/ts-miniprogram/tree/master/ts-miniprogram-base This is the end of this article about how to create a WeChat applet project using typescript. For more information about developing WeChat applet with typescript, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A brief discussion on whether MySQL can have a function similar to Oracle's nvl
>>: How to set up PostgreSQL startup on Ubuntu 16.04
View the dependent libraries of so or executable ...
1. Introduction Why do we need indexes? In genera...
1. Use the following command to set the ssh passw...
MySQL 5.7.18 installation and problem summary. I ...
First, build the case demonstration table for thi...
A long time ago, I summarized a blog post titled ...
Record the installation and configuration method ...
Configure Git environment in Docker At work, I en...
1. Reasons If the system is Centos7.3, the Docker...
Moore's Law no longer applies Starting with F...
SQL fuzzy query statement The general fuzzy state...
Preface: Sometimes in a route, the main part is t...
Nginx's configuration syntax is flexible and ...
1. Only Chinese characters can be input and pasted...
Big data continues to heat up, and if you are not...