generate types
Overview
Taq generate types
task is used to generate and export TypeScript types from compiled Michelson smart contracts. These generated types then work with your IDE and Taquito, providing type safety and an improved code authoring experience
The Michelson contracts that will be processed are those in the artifacts
folder. The default output folder will be a types
folder in the same folder as the artifacts
folder
For each contract that is processed, two output files are created:
<fileName>.types.ts
- This file contains a TypeScript definition for the contract, storage, and entrypoints and is what you will import into your TS dApp<fileName>.code.ts
- This file contains the code that is used to interact with the contract, you will not need to import this file into your TS dApp
Additionally, there are two helper files that are created:
type-aliases.ts
- This file contains the mapping from Michelson types to TypeScript types, and some helper objects that can be used to cast types (tas
), and instantiate bigMapstype-utils.ts
- This file contains methods that allow the generated types to be used directly in calls to Taquito and will need to be imported to your dApp
If changes are made to the source code of a smart contract, first it will need to be compiled again, then the types can be re-generated
Plugin Implementations
This task is implemented by the following plugins:
Plugin Name | Description |
---|---|
@taqueria/plugin-contract-types | Generates TS types from Michelson files |
Command
taq generate types [path]
Task Details
Task Name | Command | Type | Description |
---|---|---|---|
generate types | taq generate types [path] | Plugin - Code Generators | Generates TS definitions for one or more Michelson contracts |
Command-Line Arguments
Argument | Required | Description | Example Usage |
---|---|---|---|
[path] | No | Path to one or more Michelson contracts to process | taq generate types ./contracts/my-contract.jsligo |
[typeOutputDir] | No | The output folder for the .ts files generated | taq generate types --typeOutputDir ../app/types |
Aliases
The following aliases are interchangable with generate types
gen
gentypes
Usage
Description | Command | Behaviour |
---|---|---|
Generate types for all contracts | taq generate types | Generates types for each Michelson file in the /artifacts folder |
Generate types for one contract | taq generate types [path] | Generates types for the contract at the given path |
Supported Filetypes
Type | Extension |
---|---|
Michelson | .tz |