CosmWasm / ts-codegen

Convert your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
https://cosmology.zone/products/ts-codegen
Apache License 2.0
116 stars 29 forks source link

allow for simple exporting of bundles #49

Open pyramation opened 2 years ago

pyramation commented 2 years ago

scopes can be great, but let's also do something more simple, like this:

export * as FactoryContract from "./contracts/Factory.client";
export * as GovecContract from "./contracts/Govec.client";
export * as ProxyContract from "./contracts/Proxy.client";

https://github.com/nymlab/vectis/blob/b5698087fe08dade8b4ba9492889b6577369e478/cli/types/index.ts

j0nl1 commented 2 years ago

I would say there are two different issues:

  1. It doesn't export the types.
  2. It say that we are trying to use the class as a type when it is a value.

image

I think this is what happens in each scenario.

In first scenario is that you can't do spread operator for types, they will be removed because types can't be exported as constant, it should be as a module.

In second scenario what happens behind the scene when you are using the spread operator, you are cloning the govecClient but without its prototype because you are actually creating a new object. It gives the object prototype and for that reason you can't use the type of the class, it ask you to use typeof govecClient, usually you have to do that with objects.

pyramation commented 2 years ago

I think this is what happens in each scenario.

In first scenario is that you can't do spread operator for types, they will be removed because types can't be exported as constant, it should be as a module.

In second scenario what happens behind the scene when you are using the spread operator, you are cloning the govecClient but without its prototype because you are actually creating a new object. It gives the object prototype and for that reason you can't use the type of the class, it ask you to use typeof govecClient, usually you have to do that with objects.

wow thank you for the incredible details! I will be looking into this more ;)