Open gdethier opened 2 years ago
I believe the network layer ios actually problematic here, encoding things twice. Just looking at the use, it is meant to be Bytes
(as per Rust), not Opaque<Bytes>
, which makes the imOnline work, but is not really correct based on the Rust types.
So we probably need a specific override for the imOnline pallet to make the specific use there work. (And revert the type definition to match with Rust for the more general "available everywhere" case)
I'm submitting a ...
What is the current behavior and expected behavior?
When generating custom typescript definitions for a custom Substrate node using the
nodeAuthorization
pallet in its runtime, there seems to be a kind of "clash" betweennodeAuthorization
'sOpaquePeerId
andimOnline
's one. In order to prevent some double-encoding issue, we had to override (indefinitions.ts
file)OpaquePeerId
so that it is defined as aVec<u8>
(and not aWrapperOpaque<Bytes>
like inimOnline
). This works in our case because we are not using theimOnline
pallet.However, even when overriding the type definition,
imOnline
's type keeps to be imported in theaugment-*.ts
files. The only workaround we have found so far is to fix the imports manually i.e. rewrite imports likeimport type { OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
into
import type { OpaquePeerId } from './default';
In order to reproduce:
packages/node-api
yarn generate:defs-meta
You'll see that all
OpaquePeerId
are reset to point toimOnline
'sOpaquePeerId
.When a type is explicitly overridden in a definitions file, it should also be imported in the augment files.
Please tell us about your environment:
Version:
@polkadot/typegen 8.14.1
Environment:
[x] Node.js
[ ] Browser
[ ] Other (limited support for other environments)
Language:
[ ] JavaScript
[x] TypeScript 4.7.4
[ ] Other