For dfx generated files, why copy is preferred instead of an alias?


The last version I worked on IC was 0.7.2, on the latest, noticed changes, so looking at Customize the front-end :: Internet Computer noticed that a copy/rsync seems preferred instead of adding an alias generator to webpack.

Is there any particular reason for this?

It was my choice, and my thinking goes like this -

When applications get more complicated, people will get to situations where the generated types aren’t adequate, and need to be extended or manually edited. Copying the files and putting them in front of developers is a nudge in that direction. It’s a step toward less magic.

Also, aliases in webpack can’t support type inference. We have been generating typescript declarations for a while, but it wasn’t possible to take advantage of those types in your actual code without relying on fragile typescript configs and manual setup.

The new pattern allows you to import {canister_name} from "src/declarations/canister_name" and have an actor that understands your full api, with tab completion and warnings for the arguments and return types.

My full writeup on that update is here:


Ok @kpeacock, thanks for letting me know! I’ll keep that in mind.