cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
182 stars 133 forks source link

Non-index sources does not have proper typings (e.g. `@cosmos-kit/react/main/...`) #107

Open grikomsn opened 1 year ago

grikomsn commented 1 year ago

Seems that most cosmos-kit published packages is using the convention to split CommonJS and ESM sources to separate directories (https://unpkg.com/browse/@cosmos-kit/react@0.26.0/). This results in poor source typings since the path for those typings are in a different directory.

Example edge case related to #106, while import { SimpleConnectModal } from "@cosmos-kit/react/main/modal/components" does exist, TypeScript does not detect types because @cosmos-kit/react/main/modal/components types are on a different directory at @cosmos-kit/react/types/modal/components. The hacky solution is to override module declaration like below:

image

Proposed solution for this issue is to use .mjs extension for ESM sources and merge into single directory, similar to what graz does: https://unpkg.com/browse/graz@0.0.30/dist/

image

pyramation commented 1 year ago

Thanks for this solution! I think this is great. I haven't seen this .mjs before, I'm guessing we just point the module property in the package.json to the .mjs file and all just works?

I'd be down for this. I believe @NoahSaso also reported this to me over discord for another library.

I'm also guessing another solution (although not as ideal) is to copy the declarations from types into the respective folders

grikomsn commented 1 year ago

I'm also guessing another solution (although not as ideal) is to copy the declarations from types into the respective folders

I do not know how the build process works, but at Strangelove we use egoist/tsup to bundle packages, which does the heavy lifting on type declarations and outputs both CommonJS and ESM packages.

Do take a peek on graz's package output: https://unpkg.com/browse/graz@0.0.30/dist/

liujun93 commented 1 year ago

Maybe pure tsc or https://ts-morph.com/ . We'll investigate now