should.js icon indicating copy to clipboard operation
should.js copied to clipboard

Typings for custom assertions

Open dominicbartl opened this issue 7 years ago • 2 comments

Hi.

Node.js version?

8.11.1

Should.js version?

13.2.1

How to reproduce it?

When using shouldjs with Typescript and extending the should Assertions with a custom function: Lets say:

Assertion.add('asset', function() {
     this.params = { operator: 'to be asset' }

     this.obj.should.have.property('id').which.is.a.Number()
     this.obj.should.have.property('path')
})

Compiling Typescript will throw an error when using the should(obj).asset() function because it doesn't exist on the type Assertion. Simplest solution would by adding the following to the Assertion interface to allow dynamic properties:

[key: string]: any;

dominicbartl avatar May 02 '18 13:05 dominicbartl

I do not think this is a right idea. If i add such entry to typings it will be possible to call any sort of method. Even that does not exists.

btd avatar May 03 '18 05:05 btd

@btd totally agree. This is just the first idea I came up with to keep the standard assertions and allow custom ones as well

dominicbartl avatar May 03 '18 07:05 dominicbartl