polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 349 forks source link

type <t> does not satisfy the constraint 'INumber' #4675

Closed cinlk closed 2 years ago

cinlk commented 2 years ago

package version: @polkadot/api@7.13.1, @polkadot/types-codec@7.13.1,@polkadot/types@7.13.1

I am running the command "ts-node --skip-project node_modules/@polkadot/typegen/scripts/polkadot-types-from-chain.cjs --package '.' --endpoint ./packages/types/src/metadata/meta.json --output ./packages/types/src/interfaces" to generate 'augment-api-*' files. The 'augment-api-tx.ts' file has some strange errors that each of generic type 'Compact ' of 'T' dose not satisfy constraint 'INumber'.

such asCompact<ReferendumIndex> Compact<u32> Compact<ReferendumIndex> Compact<BalanceOf> Compact<Balance> etc

jacogr commented 2 years ago

You will need to provide an example of the output and the error line.

cinlk commented 2 years ago

// Auto-generated via yarn polkadot-types-from-chain, do not edit / eslint-disable /

import type { EthereumBlockNumber, EthereumHeader, EthereumReceiptProof, EthereumReceiptProofThing, EthereumRelayHeaderParcel, EthereumRelayProofs, KtonBalance, MMRProof, RedeemFor, RelayAuthoritySignature, RelayAuthoritySigner, RingBalance, StakingBalanceT, TsInMs } from './darwiniaInject'; import type { RelayAffirmationId } from './relayerGame'; import type { ApiTypes } from '@polkadot/api-base/types'; import type { Data } from '@polkadot/types'; import type { Bytes, Compact, Option, U256, U8aFixed, Vec, bool, u16, u32, u64, u8 } from '@polkadot/types-codec'; import type { AnyNumber, ITuple } from '@polkadot/types-codec/types'; import type { BabeEquivocationProof, NextConfigDescriptor } from '@polkadot/types/interfaces/babe'; import type { BridgedHeader, InboundRelayer, InitializationData, LaneId, MessageNonce, MessagesDeliveryProofOf, MessagesProofOf, OperatingMode, OutboundMessageFee, OutboundPayload, Parameter, UnrewardedRelayersState } from '@polkadot/types/interfaces/bridges'; import type { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective'; import type { AccountVote, Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy'; import type { Renouncing } from '@polkadot/types/interfaces/elections'; import type { EthereumAddress } from '@polkadot/types/interfaces/eth'; import type { Signature } from '@polkadot/types/interfaces/extrinsics'; import type { GrandpaEquivocationProof, GrandpaJustification, KeyOwnerProof } from '@polkadot/types/interfaces/grandpa'; import type { IdentityFields, IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity'; import type { Heartbeat } from '@polkadot/types/interfaces/imOnline'; import type { ProxyType } from '@polkadot/types/interfaces/proxy'; import type { AccountId, Balance, BalanceOf, BlockNumber, BlockNumberFor, Call, CallHashOf, ChangesTrieConfiguration, H160, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, Weight } from '@polkadot/types/interfaces/runtime'; import type { Period, Priority } from '@polkadot/types/interfaces/scheduler'; import type { Keys } from '@polkadot/types/interfaces/session'; import type { SocietyJudgement } from '@polkadot/types/interfaces/society'; import type { ElectionScore, EraIndex, RawSolution, RewardDestination, SolutionOrSnapshotSize, Supports, ValidatorPrefs } from '@polkadot/types/interfaces/staking'; import type { Key } from '@polkadot/types/interfaces/system'; import type { BountyIndex } from '@polkadot/types/interfaces/treasury'; import type { Timepoint } from '@polkadot/types/interfaces/utility'; import type { VestingInfo } from '@polkadot/types/interfaces/vesting';

declare module '@polkadot/api-base/types/submittable' { export interface AugmentedSubmittables { authorship: { /**

These functions from above code containing generic type as "Compact\<T>" T is from runtime type show the error.

jacogr commented 2 years ago

This is the exact same form used eg. here -

https://github.com/polkadot-js/api/blob/2b1a7da4468bb71e4fb122a1e70df42f9930be66/packages/api-augment/src/substrate/tx.ts#L627

Which version of TypeScript are you using? Could be related to https://polkadot.js.org/docs/usage/FAQ#under-typescript-i-have-ts-compilation-errors

cinlk commented 2 years ago

4.6.2

This is the exact same form used eg. here -

https://github.com/polkadot-js/api/blob/2b1a7da4468bb71e4fb122a1e70df42f9930be66/packages/api-augment/src/substrate/tx.ts#L627

Which version of TypeScript are you using? Could be related to https://polkadot.js.org/docs/usage/FAQ#under-typescript-i-have-ts-compilation-errors

4.6.2

jacogr commented 2 years ago

Honestly have no idea as to the why in this case.

scglenn commented 2 years ago

Im getting the same issues, polkadot.js/api has tons of type issues in typescript

Edit: I replaced import { ApiPromise } from "@polkadot/api"; with const { ApiPromise } = require("@polkadot/api");

and it built

polkadot-js-bot commented 2 years ago

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

fend25 commented 2 years ago

@scglenn @cinlk

Please try to add tsconfig flags: "allowSyntheticDefaultImports": true or "esModuleInterop": true

polkadot-js-bot commented 2 years ago

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

polkadot-js-bot commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.