# How to generate TypeScript canister API description not through DFX?

**URL:** <https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490>\
**Category:** Motoko\
**Created:** [July 19, 2023, 1:42am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490 "2023-07-19T01:42:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [July 19, 2023, 1:42am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490/1 "2023-07-19T01:42:26Z")

</div>

As I told in [my previous question](https://forum.dfinity.org/t/how-to-generate-did-files-for-an-actor-class/21468), 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`

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [July 19, 2023, 1:51am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490/2 "2023-07-19T01:51:42Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [July 19, 2023, 6:48am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490/3 "2023-07-19T06:48:14Z")

</div>

You can use `didc bind --target ts`. didc can be downloaded [here](https://github.com/dfinity/candid/releases)

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [July 19, 2023, 7:15am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490/4 "2023-07-19T07:15:17Z")

</div>

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](https://github.com/dfinity/ic-js/blob/main/scripts/compile-idl-js)

---

<div class="post-metadata">

**Author:** ![jebitok-dev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jebitok-dev/32/13330_2.png) [@jebitok-dev](https://forum.dfinity.org/u/jebitok-dev)\
**Post date:** [October 24, 2023, 9:01am UTC](https://forum.dfinity.org/t/how-to-generate-typescript-canister-api-description-not-through-dfx/21490/5 "2023-10-24T09:01:18Z")

</div>

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] 🔨 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.
