api icon indicating copy to clipboard operation
api copied to clipboard

How to use the metadata type in a custom type?

Open 0xverin opened this issue 2 years ago • 0 comments

  • I'm submitting a ...
  • [ ] Bug report
  • [ ] Feature request
  • [x] Support request
  • [ ] Other
  • What is the current behavior and expected behavior?
export default {
    types: {
        VCRequested: {
            xxx: "xxx",
            assertion: "Assertion",
        },
        Assertion: {
            xxxx: "xxx"
        }
    }
}

As shown in the above code, Assertion is my custom type, but there is a CorePrimitiveAssertion type within metadata that is identical to Assertion. I want to directly replace it with CorePrimitiveAssertion, but when generating types, I get an error:

build/interfaces/vc/types.ts:266:25 - error TS2304: Cannot find name 'CorePrimitiveAssertion'.

266     readonly assertion: CorePrimitiveAssertion;
                            ~~~~~~~~~~~~~~~~~~~~~~

It seems that CorePrimitiveAssertion is not automatically imported into the generated types.If I manually import the following code in this file, it all works:

import type { CorePrimitivesAssertion } from '@polkadot/types/lookup';

All other types work fine. I just want to replace an existing type in metadata within a custom type. Is this achievable?

  • Please tell us about your environment:
  • Version:

"@polkadot/api": "^10.9.1"

  • Environment:

    • [x] Node.js
    • [ ] Browser
    • [ ] Other (limited support for other environments)
  • Language:

    • [ ] JavaScript
    • [x] TypeScript (include tsc --version)
    • [ ] Other

0xverin avatar Jan 15 '24 12:01 0xverin