moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

Add Typescript definition file #48

Closed KarlPurk closed 8 years ago

KarlPurk commented 8 years ago

This PR adds a first attempt at a typescript definition file. This has been created by hand, perhaps auto-generation would be a better solution as mentioned in #37.

I've followed the recommended approach of using the documentation to drive the creation of the definition file. Some errors may have slipped through, a review of the annotations would be a good idea.

I've added support for the following primitive types string, boolean, number and array, enabling the following:

// Global augmentation support
(1).must.be.a.number();
"1".must.be.a.string();
(true).must.be.a.boolean();
([1]).must.be.an.array();

// Expect syntax support
var something: boolean = true;
expect(something).to.be.true();

This would benefit from some tests to verify the definition matches the expected API. However, I've not looked into testing definition files yet. Fixes #37.

moll commented 8 years ago

Cool. That is pretty sweet. Thank you! I don't have a TypeScript setup here yet, so I'll trust you. How about we name it must.d.ts to match the main file and I'll get it out there.

Do you have any idea how to autogenerate it for the future based on JSDocs, too?

KarlPurk commented 8 years ago

I've renamed the definition file to must.d.ts.

I've not really looked into auto generating a definition file but a quick google reveals a stack overflow post with some potential leads: http://stackoverflow.com/questions/18301898/generating-typescript-declaration-files-from-javascript

If I find myself with some spare time I'll look into further.

moll commented 8 years ago

Thanks again, Karl! I'll cut a release in the morning.

A quick Q: The TypeScript compiler picks up the definitions automatically now that there's the typings package.json property, right? And does the global declaration need one for Object, too, or is that somehow implied?

KarlPurk commented 8 years ago

No problem Andri!

A quick Q: The TypeScript compiler picks up the definitions automatically now that there's the typings package.json property, right?

Yes, that's correct.

And does the global declaration need one for Object, too, or is that somehow implied?

Yes, it does, well spotted :) I can submit a patch for this if you want?

I'm going to look into testing definition files soon, when I do, I can create a set of tests to validate the definitions if you'd be happy accepting them?

Looking forward to the next release!

moll commented 8 years ago

Yes, it does, well spotted :) I can submit a patch for this if you want?

That'd be lovely. Thanks! You've got your [repo] mirror set up already, so go ahead, let me know and I'll pull from that.