Canister Types File Does Not Include idlFactory or canisterId Exports


I am having a little bit of trouble coming up with the best way to address an issue I ran into with using the typings file generated during the canister build of the dfx sample app. I downloaded the latest release of candid cli (didc 0.1.0) to see if the behavior was the same there and it looks like it is.

The types file does not include the following exports of the associated module in the same directory. These export names appear to be static and I was wondering if there is a reason these weren’t included in the generated types file by the didc tool.

  • export const idlFactory: any;
  • export const canisterId: string;

It seems that the suggested approach is to declare a module with this definition:
declare module ‘dfx-generated/hello’ {
export const idlFactory: any;
export const canisterId: string;

I was able to do this, but then was getting issues with using typings from the types file. So, I decided to create multiple paths for the same module in the tsconfig.json to allow using both the declared module and generated types file separately for the appropriate imported items:
“paths”: {
“dfx-generated/": [".dfx/local/canisters/hello/”],
“dfx-service/": [".dfx/local/canisters/hello/”]

Here is a sample project and branch that shows the workaround approach:

I recently came up with a couple of npm scripts to remove some of the convoluted set up required in the initial workaround. This solution requires using the deploy script for deploying the Hello canister, so that the postdeploy script can add the above mentioned exports to the generated types file. This can be found in another branch of the same project:

Is there a more straightforward solution or a better alternative that I am missing? I am using Angular CLI 12 with no access to the webpack config being used. I was planning to find a more dynamic approach to the paths, but for now am just trying to get by :slight_smile:

Any help is greatly appreciated.