Skip to main content

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 bigMaps
  • type-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
note

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 NameDescription
@taqueria/plugin-contract-typesGenerates TS types from Michelson files

Command

taq generate types [path]

Task Details

Task NameCommandTypeDescription
generate typestaq generate types [path]Plugin - Code GeneratorsGenerates TS definitions for one or more Michelson contracts

Command-Line Arguments

ArgumentRequiredDescriptionExample Usage
[path]NoPath to one or more Michelson contracts to processtaq generate types ./contracts/my-contract.jsligo
[typeOutputDir]NoThe output folder for the .ts files generatedtaq generate types --typeOutputDir ../app/types

Aliases

The following aliases are interchangable with generate types

  • gen
  • gentypes

Usage

DescriptionCommandBehaviour
Generate types for all contractstaq generate typesGenerates types for each Michelson file in the /artifacts folder
Generate types for one contracttaq generate types [path]Generates types for the contract at the given path

Supported Filetypes

TypeExtension
Michelson.tz