Do we have to generate Typescript types manually?

Hi,

Looking at the CanCan example typyings.d.ts ( cancan/typings.d.ts at main · dfinity/cancan · GitHub ), was it generated programmatically or was it written by hand? Is there a way to do it automatically?

Thank you!

2 Likes

Interesting. So, I found the d.ts files in the .dfx directory; but why would the CanCan project have the .d.ts in the source directory if this exists in the .dfx directory?

So, opened both files and noticed that they are indeed, different. Wonder in which use-case they’re suitable for.

It was a binding generated using the candid tool didc, which now has compiled releases here:
https://github.com/dfinity/candid/releases

You can use the tool to do the same for your own projects, passing in the .did file generated by dfx. Eg:

didc bind hello.did -t ts

Docs for this here:
https://github.com/dfinity/candid/tree/master/tools/didc

3 Likes

There are some situations where it’s applicable. It’s necessary if you have an app that serves the frontend and the backend from the same canister, which is what we do in the Internet Identity project.

Manually generating your files can also make it possible to rely on less configuration in webpack, tsconfig, jest, and so on

We have a planned feature to add a simple command for it to dfx so you don’t have to independently download didc.

5 Likes

Thank you! The cmd in the dfx sounds good and is going to be very useful :slight_smile:

Thank you very much @Ori !

1 Like