Open treybrisbane opened 4 years ago
Webpack supports similar functionality with
webpack.config.ts
files (although I believets-node
is required for those).
Yea, this is the kicker.
AVA needs to first resolve the configuration, to then determine whether to load @ava/typescript
.
I suppose we could resolve ava.config.ts
files, then load @ava/typescript
, and then somehow load the configuration.
But we'd have to compile the file which is another complication. I'm not sure it's worth it, as nice as it would be to have a type definition for the config.
@novemberborn I believe that there are two separate ideas here. Firstly, whether ava should support ava.config.ts
files for configuration. Secondly, should ava configurations have type definitions. I believe that the second idea is easier to implement than the first, and useful to a wider array of users.
For the record, AVA 4 now lists @ava/typescript
as an optional Peer Dependency. That should make this feature somewhat easier to implement.
Secondly, should ava configurations have type definitions. I believe that the second idea is easier to implement than the first, and useful to a wider array of users.
How would this work in practice, in JS files?
JSDoc comments. I use them very often.
/**
* @type {import('ava').Config}
*/
const config = {};
module.exports = config;
A little awkward, but it would then provide auto-completion and whatnot so that's cool!
PR welcome, even if it's an incomplete starting point. Note that we also support a config factory.
That said, this needs to be added in https://github.com/avajs/ava.
There's also another solution that I've seen a couple places (vite, nextjs). AVA would export a defineConfig
function, which takes a config
parameter and exports it directly. The trick is that you can add a type definition to the config
parameter.
Importing ava
itself doesn't quite work (it expects to be imported in a test worker). We could have an ava/config
export though.
It'd be useful if we could use TypeScript to define our Ava configurations via an
ava.config.ts
file.Ideally, we'd be able to structure them like so:
Webpack supports similar functionality with
webpack.config.ts
files (although I believets-node
is required for those).