Skip to content

Conflict with Chai assert / changing a keyword #68

@miohtama

Description

@miohtama

This is not strictly espower-typescript specific issue, but maybe you can help.

I am using truffle-typing package to bring some TypeScript definitions into my tests. However, these definitions already declare assert from Chai.

If I try to add import assert = require('assert'); in my test.ts, TypeScript compiler will balk.


TSError: ⨯ Unable to compile TypeScript:
test/Token.spec.ts:4:7 - error TS2451: Cannot redeclare block-scoped variable 'assert'.

4 const assert = require("assert"); // Power assert https://github.com/power-assert-js/espower-typescript
        ~~~~~~

  node_modules/truffle-typings/index.d.ts:10:15
    10 declare const assert: Chai.AssertStatic;
                     ~~~~~~
    'assert' was also declared here.

I was thinking a workaround of using some different symbol for assert from power-assert, e.g.

 asrt = require("assert"); // Power assert aliased

...but I am not sure if this is going to work due to transpiling.

Can I change the keyword power-assert is using in TypeScript somehow?

Namely, the following does not give me power-assert output:

// test/test.ts
import asrt = require('assert'); // If I rename assert -> asrt power-assert is no longer triggered

describe('Array#join', () => {
  it('joins all elements into a string with separator', () => {
    asrt(['a', 'b', 'c'].join(':') === 'a:b:c:');
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions