Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truffle(@next) does not find any migrations with .ts extension #2

Open
roderik opened this issue Oct 21, 2018 · 5 comments
Open

Truffle(@next) does not find any migrations with .ts extension #2

roderik opened this issue Oct 21, 2018 · 5 comments

Comments

@roderik
Copy link

roderik commented Oct 21, 2018

It can be configured with https://github.com/trufflesuite/truffle/blob/46fc7bdb9fde7cc3fa99b94fef04b1d6c04c38f7/packages/truffle-migrate/index.js#L30 but I have not figured out how to set it

@roderik
Copy link
Author

roderik commented Oct 21, 2018

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/**/*"]
}

@roderik
Copy link
Author

roderik commented Nov 22, 2018

My fix PR was merged in the latest truffle beta

@roderik roderik closed this as completed Nov 22, 2018
@roderik
Copy link
Author

roderik commented Nov 23, 2018

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.

@roderik roderik reopened this Nov 23, 2018
@ryanleecode
Copy link

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");

@krzkaczor
Copy link
Member

krzkaczor commented Apr 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants