How to generate TypeScript canister API description not through DFX?

As I told in my previous question, I need to generate TypeScript API for my actor class that is not included into dfx.json (because it is to be created by other Motoko code, not directly by DFX).

I figured out how to create the *.did file. But how to create the rest TS/JS code?

This is the files that DFX generates and I need to generate having only source and .did file (not by DFX):

  • *.did
  • *.did.d.ts
  • *.did.js
  • *.d.ts
  • *.js

dfx deploy has some Post processing candid file stage. Apparently, it is what I need.

How to run this stage manually (for a canister not specified in dfx.json)? I don’t know which command to use for this.

You can use didc bind --target ts. didc can be downloaded here

For what is worth, I add those types of canister to my dfx.json configuration as well. That way it generates the types automatically. I just have to not care about the fact they fail at deploy locally but the advantage, is that all my commands (cargo test and npm run generate) remains to same to generate the types no matter what.

Alternatively, we got a script in ic-js that generates types from did files: https://github.com/dfinity/ic-js/blob/main/scripts/compile-idl-js

I have a challenge running dfx deploy This is my current error message

dfx deploy
Deploying all canisters.
All canisters have already been created.
Building canisters…
Executing ‘npx azle message_board’

Building canister message_board

[1/2] :hammer: Compiling TypeScript…
thread ‘main’ panicked at ‘SourceAnnotation range (4, 15) is bigger than source length 12’, /home/jebitok/.config/azle/1.68.2/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.9.1/src/display_list/from_snippet.rs:286:9
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Compilation failed with status: 101
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
Failed to build all canisters.
Failed while trying to build all canisters.
The build step failed for canister ‘bkyz2-fmaaa-aaaaa-qaaaq-cai’ (message_board) with an embedded error: Failed to build custom canister message_board.: Failed to run npx azle message_board.: The custom tool failed.