Closed aaroncox closed 3 months ago
More information, since I ran into it again.
"target": "es2021"
seems to be the last working version it breaks again in es2022
."useDefineForClassFields": true
is set, it also happens.I faced a similar issue when exploring the usage of a via CLI generated contract file in an example app included in the wharfkit-wallet-plugin-template where following tsconfig.json
is used:
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
the tsconfig.node.json
is:
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
I generated the contract for atomicmarket
with CLI version 2.6.3
and I try to fetch the market balances as follows:
import { APIClient as AntelopeAPIClient } from '@wharfkit/antelope'
import { Contract as AtomicMarketContract } from "./atomicmarket"
const antelopeClient = new AntelopeAPIClient({ url: "https://proton.eosusa.io" })
const amContract = new AtomicMarketContract({client: antelopeClient, account: 'atomicmarket'})
const userBalance = await amContract.table('balances').get(session!.actor.toString())
console.log(userBalance)
the output of (an existing balance row) is:
balances_s {owner: undefined, quantities: undefined}
I was able to get it working with es2022
but I also saw failures with "useDefineForClassFields": true
and I needed to explicitly set it to false "useDefineForClassFields": false
since the base tsconfig sets that property to true
.
I think I figured this out - it's the outputted struct classes and incompatibility with useDefineForClassFields
.
Take for example this struct:
@Struct.type('propose')
class Propose extends Struct {
@Struct.field(Name) proposer!: Name
}
With useDefineForClassFields: true
this is going to return undefined
as the values.
However, if you change the struct to the format below, the values now populate correctly.
@Struct.type('propose')
class Propose extends Struct {
@Struct.field(Name) declare proposer: Name
}
It's prepending the property name with declare
and removing the !
after it.
Any already generated structs will need to be modified to include this change.
We'll update our libraries and make the command line tools use this syntax.
The wharfkit/cli
toolkit now uses the new syntax as described above. I think we can finally close this one out.
If there's any instances of this still happening - feel free to reopen the issue.
Just stumbled into this in a nodejs project, when setting
"target": "esnext"
in thetsconfig.json
, it prevents some structs from rendering properly.Sample code:
This causes the output to be:
However when I switch to using
"target": "es2020"
, the same code above outputs:Not sure what in
esnext
breaks this, and not sure if we need to fix - but recording here for sake of jotting it down somewhere.