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

Use with TypeScript #12

Closed
Merott opened this Issue Oct 20, 2015 · 5 comments

Comments

Projects
None yet
6 participants
@Merott
Copy link

Merott commented Oct 20, 2015

How would one go about using dirty-chai with TypeScript? Can you provide some guidance on how to set up the typings?

@joshperry joshperry closed this Jun 1, 2016

@olingern

This comment has been minimized.

Copy link

olingern commented Jun 15, 2017

Any reason this was closed? I'm running into function signature issues (in typescript). If it's not currently supported, can you guys list it under the caveats?

@joshperry

This comment has been minimized.

Copy link
Member

joshperry commented Jun 16, 2017

Hey guys,

This issue had sat for 2 years and so I figured I'd close it. Personally I don't have the time or experience to implement TypeScript support so I'm not really qualified to assist here, I had hoped that someone from the community would be able to invest some time if it was important enough.

I've reopened the issue so that others in the community can see that this is a desire, but I unfortunately have no timeline for providing TypeScript support beyond that.

Cheers!

@Pencroff

This comment has been minimized.

Copy link

Pencroff commented Nov 12, 2017

Approach one:

Use error message like:

expect(false).to.be.true('Not true');

Approach two:

Create in your local project folder types in root (the same level with tsconfig.json)
Put path to it in your tsconfig.json like:

"compilerOptions": {
...
  "typeRoots": ["node_modules/@types", "types"],
...
}

and then create in types new file dirty-chai.d.ts like below

import Assertion = Chai.Assertion;

declare namespace Chai { // tslint:disable-line
  export interface Assertion {
    (message?: string): Assertion;
  }
}

After you shouldn't have warning like Expected 1-2 arguments, but got 0 for code like
expect(false).to.be.true();

@janiukjf

This comment has been minimized.

Copy link

janiukjf commented Apr 12, 2018

I actually expanded on this and exported it properly so that VSCode sees it as proper typings for the import.

// Type definitions for dirty-chai

/// <reference types="chai" />

import Assertion = Chai.Assertion;

declare namespace Chai { // tslint:disable-line
  interface Assertion {
    (message?: string): Assertion;
  }
}

declare const dirtyChai: Chai.Assertion;

declare module "dirty-chai" {
  export = dirtyChai;
}

Once you do that, VSCode or other editors should resolve that these typings are actually for dirty-chai. I went with the standard folder structure of typings/dirty-chai/index.d.ts. Either file structure works though.

@pgraham

This comment has been minimized.

Copy link

pgraham commented Aug 30, 2018

In order to get this to work I had to put the following in types/dirty-chai/index.d.ts:

// tslint:disable
// Type definitions for dirty-chai

/// <reference types="chai" />

import Assertion = Chai.Assertion

declare namespace Chai {
  export interface Assertion {
    (message?: string): Assertion;
  }
}

declare module "dirty-chai" {
  function dirtyChai(chai: any, utils: any): void
  namespace dirtyChai {  }
  export = dirtyChai
}

Also might be helpful: https://gist.github.com/nwronski/9bf443a61a4c310675a91da8bb635384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.