Skip to main content

Synchronization model definition

To enhance developers' code writing experience, cloud data models can be synchronized to local type definition files, enabling intelligent type hints and checks in the code editor. The post-synchronization effect 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:

  1. For WeChat Mini Programs, run the command in the same directory as the app.json file.
  2. For WeChat Cloud Development Cloud Functions, run the command in the cloudfunctions/<functions folder> directory.
  3. First run requires specifying the environment ID parameter --envId=<envId>, and subsequent runs do not require specifying it again.
  4. Running tcb requires login. For users of WeChat Cloud Development, please select the [Mini Program Official Account] login method during sign-in.

Method 1: Run the tcb command directly with npx

This method is only applicable when tcb is not installed locally. If tcb is already installed locally, please use Method 2

Go 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 of tcb is <2.4, execute the following command to install or upgrade it.

npm i @cloudbase/cli -g

Go 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 hints in the code editor

  1. Ensure the @cloudbase/wx-cloud-client-sdk module is properly installed.
  2. Ensure the tsconfig.json file is configured correctly:
{
"compilerOptions": {
"allowJs": true
}
}