GithubHelp home page GithubHelp logo

Comments (5)

roderik avatar roderik commented on June 20, 2024

Workaround:

set migrations_directory: './dist', in truffle.js
add this to package.json scripts

    "build:truffle": "truffle compile",
    "build:contracts": "typechain --target truffle './build/contracts/*.json'",
    "build:ts": "tsc --declaration",
    "build": "npm run build:truffle && npm run build:contracts && npm run build:ts",

and run npm run build && truffle migrate

I use this tsconfig file

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "ES2017",
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "skipLibCheck": true,
    "paths": {
      "*": ["node_modules/*", "types/*"]
    }
  },
  "exclude": ["dist/**/*"]
}

from truffle-typechain-example.

roderik avatar roderik commented on June 20, 2024

My fix PR was merged in the latest truffle beta

from truffle-typechain-example.

roderik avatar roderik commented on June 20, 2024

While I can now select .ts files, it freaks out on imports

import { MigrationsContract } from '../types/truffle-contracts/index';
const Migrations: MigrationsContract = artifacts.require('./Migrations.sol');

const migration: Truffle.Migration = async (deployer: Truffle.Deployer) => {
  await deployer.deploy(Migrations);
};

module.exports = migration;

// because of https://stackoverflow.com/questions/40900791/cannot-redeclare-block-scoped-variable-in-unrelated-files
export {};

Without the MigrationsContract the artifacts.require returns an 'any' which does not help me at all in making my migrations strongly typed.

from truffle-typechain-example.

ryanleecode avatar ryanleecode commented on June 20, 2024

Using jsdoc comments might be a decent work around for now. You can still import the generated typings.

Example:

import {
  ConvertLibContract,
  MetaCoinContract
} from "../types/truffle-contracts";

/**
 * @type {ConvertLibContract}
 */
var ConvertLib = artifacts.require("./ConvertLib.sol");

/**
 * @type {MetaCoinContract}
 */
var MetaCoin = artifacts.require("./MetaCoin.sol");

from truffle-typechain-example.

krzkaczor avatar krzkaczor commented on June 20, 2024

The problem with:

var ConvertLib = artifacts.require("./ConvertLib.sol");

is that you need to use artifact name like this instead:

var ConvertLib = artifacts.require("ConvertLib");

But anyway, I can't get it to work as files don't seem to be transpiled on the fly... I am not sure why. @roderik any ideas?

dethcrypto/TypeChain@7d34010

from truffle-typechain-example.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.