chai icon indicating copy to clipboard operation
chai copied to clipboard

Officia type definitions for 5.x?

Open justinfagnani opened this issue 1 year ago • 15 comments

I notice that there are no type definitions for the 5.x branch, here or in Definitely Typed. Is there a chance of getting official types with the 5.x releases?

justinfagnani avatar Dec 20 '23 22:12 justinfagnani

PRs welcome for adding official types.

keithamus avatar Dec 21 '23 11:12 keithamus

we could generate types via --declarationOnly in tsc if we correct all the jsdoc, but its a chunky job

so maybe for now we just store hand written types alongside the sources? i can probably have a stab at it at some point

43081j avatar Dec 21 '23 12:12 43081j

I'm hesitant to ask, but... it's there any appetite for a contribution of a port of the source to TypeScript syntax?

justinfagnani avatar Dec 21 '23 16:12 justinfagnani

Tbh I would rather do that than work around it producing types from the js

If everyone's up for that I can probably sort it out

43081j avatar Dec 21 '23 16:12 43081j

I could contribute too, though you might be faster.

I wonder if given the existing npm scripts, if Wireit would be a good addition to make sure everything's built before other scripts that need that.

justinfagnani avatar Dec 21 '23 19:12 justinfagnani

Started a draft PR here. I'll be slogging through the types and trying to get them all done before the new year but who knows how long it will take :D

https://github.com/chaijs/chai/pull/1557

Feel free to help out by making PRs against this one.

koddsson avatar Dec 28 '23 09:12 koddsson

Any updates here? The lack of TS definitions for v5 makes it harder to adopt this version in TS codebases.

FWIW, the following patch seems to do the minimum work needed to import assert and expect from a TS file.

-declare const chai: Chai.ChaiStatic;
-
-declare module "chai" {
-    export = chai;
-}
+export const assert: Chai.AssertStatic;
+export const expect: Chai.ExpectStatic;

freshp86 avatar Jun 25 '24 23:06 freshp86

i have a branch where i was working on converting the codebase to typescript overall, but i think @koddsson, @keithamus and i should really catch up on this

we need to decide if to provide a fixed set of types as step 1, then move to typescript. or just go all in and move to typescript

43081j avatar Jun 26 '24 15:06 43081j

we need to decide if to provide a fixed set of types as step 1, then move to typescript

This seems like the best option to me.

... or just go all in and move to typescript

Blocking v5 TS definitions on the whole project moving to TS seems a bit unnecessary. As shown above manually crafting a d.ts file to properly reflect the newly exposed ES modules seems much easier (perhaps even trivial?) than migrating the whole project to TS and then relying on automatic .d.ts generation.

freshp86 avatar Jun 28 '24 21:06 freshp86

i think you're right

i have a bunch of travel in the coming weeks but ill try find time to at least sort out a types-only branch (before moving to typescript as a whole)

contributions welcome too of course, but im thinking we may as well roughly copy whats in my ts branch

43081j avatar Jun 28 '24 23:06 43081j