Synchronous Model Definition
To enhance developers' coding experience, users' cloud data models can be synchronized to local type definition files, enabling intelligent type hints and checks in the code editor. The effect after synchronization is as follows:
Data Model Intelligent Hints
Field Intelligent Hints
Synchronization Process
Select any of the following methods to synchronize the data model definition:
Note:
- For WeChat Mini Programs, the command needs to be run in the same directory as the
app.json
file.- For WeChat Cloud Development cloud functions, the command needs to be run in the
cloudfunctions/<functions folder>
directory.- The first run requires specifying the environment ID parameter
--envId=<envId>
, subsequent runs do not require it.- Running tcb requires login. For WeChat Cloud Development, please select the [Mini Program Official Account] login method.
Method 1: Run the tcb command directly with npx
This method is only applicable when
tcb
is not installed locally. Iftcb
is already installed locally, please use Method 2
Navigate to the project directory (refer to the notes for directory location), then execute the following command.
npx --package=@cloudbase/cli tcb sync-model-dts --envId=<envId>
Method 2: Install the tcb Command-Line Tool
If
tcb
is not installed locally or the installed version is <2.4, execute the following command to install or upgrade
npm i @cloudbase/cli -g
Navigate to the project directory (refer to the notes for directory location), then execute the following command.
tcb sync-model-dts --envId=<envId>
Common Issues and Solutions
Issue: No Model Prompts in Code Editor
- Ensure the
@cloudbase/wx-cloud-client-sdk
module is properly installed. - Ensure the
tsconfig.json
file is configured correctly:
{
"compilerOptions": {
"allowJs": true
}
}