paritytech / capi

[WIP] A framework for crafting interactions with Substrate chains
https://docs.capi.dev
Apache License 2.0
105 stars 10 forks source link

capi/known is missing #223

Open crystalin opened 2 years ago

crystalin commented 2 years ago

I following the readme of the repo and ended up with this exemple:

import * as C from "capi";
import { polkadot } from "capi/known";

const main = async () => {
    const chain = C.chain(polkadot);

    const alicePublicKey = chain.address.alice.asPublicKeyBytes();

    const value = await chain
    .pallet("System")
    .entry("Account", alicePublicKey)
    .read();
}

main();

(on node v16)

and ts fails with:

    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/tools/capi-test.ts:2:26 - error TS2307: Cannot find module 'capi/known' or its corresponding type declarations.

2 import { polkadot } from "capi/known";
                           ~~~~~~~~~~~~
src/tools/capi-test.ts:8:34 - error TS2339: Property 'address' does not exist on type 'Chain<any>'.

8     const alicePublicKey = chain.address.alice.asPublicKeyBytes();
                                   ~~~~~~~
harrysolovay commented 2 years ago

Hi, @crystalin.

The error likely stems from your module resolution strategy (defined as moduleResolution in your tsconfig). Unless set to NodeNext or Node16, the resolution of non-root exports fails. This is true across Node+TS projects, regardless of Capi usage or lack thereof.

There is a relevant issue I'd like to point out, incase you have a preference on the best path forward. I can imagine other devs will run into this pain point as well, so we certainly need to fine-tune this part of the experience before a first stable release.

We still have some development ahead of us before Capi is ready for the prime time; there will be breaking changes. That being said, testing & feedback is greatly appreciated (thank you!); please let us know how we can ensure Capi ultimately meets your needs.