chaijs / chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
https://chaijs.github.io
MIT License
8.11k stars 696 forks source link

Officia type definitions for 5.x? #1554

Open justinfagnani opened 9 months ago

justinfagnani commented 9 months ago

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?

keithamus commented 8 months ago

PRs welcome for adding official types.

43081j commented 8 months ago

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

justinfagnani commented 8 months ago

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

43081j commented 8 months ago

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

justinfagnani commented 8 months ago

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.

koddsson commented 8 months ago

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.

freshp86 commented 2 months ago

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;
43081j commented 2 months ago

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

freshp86 commented 2 months ago

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.

43081j commented 2 months ago

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

tpluscode commented 2 weeks ago

Thought I'd give DT a go https://github.com/DefinitelyTyped/DefinitelyTyped/pull/70397 before chai is migrated. And the type packages which depend on chai will need to be updated anyway so..

cc @43081j

43081j commented 2 weeks ago

Oof that's a chunky change 😅 I'll have a read through it when I can

I'm planning on working on shipping types with chai pretty soon too, but not through my ts conversion. Initially just hand writing them (from my branch)

tpluscode commented 2 weeks ago

The changes to chai itself aren't that big. But all the related packages 😵‍💫

tpluscode commented 1 week ago

@43081j following the advice from @andrewbranch on DT, I would also propose the same, that should chai bundle its own types at some point, you'd keep the global Chai namespace. Other way will likely be a breaking change, similarly to what I initially did in that PR. Keeping the global NS will help with backward compatibility.