tact
tact copied to clipboard
Returning `self` from getters
The following contract compiles, but produces a TS error:
import "@stdlib/deploy";
contract Test with Deployable {
id: Int as uint32 = 0;
anotherData: Cell;
init() {
self.anotherData = beginCell().endCell();
}
get fun contractData(): Test {
return self;
}
}
Test:
import { Blockchain, SandboxContract, TreasuryContract } from '@ton/sandbox';
import { toNano } from '@ton/core';
import { Test } from '../wrappers/Test';
import '@ton/test-utils';
describe('Test', () => {
let blockchain: Blockchain;
let deployer: SandboxContract<TreasuryContract>;
let test: SandboxContract<Test>;
beforeEach(async () => {
blockchain = await Blockchain.create();
test = blockchain.openContract(await Test.fromInit());
deployer = await blockchain.treasury('deployer');
const deployResult = await test.send(
deployer.getSender(),
{
value: toNano('0.05'),
},
{
$$type: 'Deploy',
queryId: 0n,
}
);
expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: test.address,
deploy: true,
success: true,
});
});
it('should get data', async () => {
const data = await test.getContractData();
console.log(data);
});
});