Skip to content

Commit

Permalink
Refactor type definition
Browse files Browse the repository at this point in the history
* Split across multiple files.

* Rename types, most noticeably `TestInterface` is now `TestFn`, but
really anything that had the Interface suffix has been changed.

* Update some documentation.
  • Loading branch information
novemberborn committed Jul 10, 2021
1 parent fe12bd4 commit 4b4b2f6
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 646 deletions.
11 changes: 5 additions & 6 deletions .xo-config.json
Expand Up @@ -23,13 +23,12 @@
},
"overrides": [
{
"files": "index.d.ts",
"files": [
"index.d.ts",
"types/*.d.ts"
],
"rules": {
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/method-signature-style": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/unified-signatures": "off"
"import/extensions": "off"
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/recipes/typescript.md
Expand Up @@ -186,10 +186,11 @@ test('providedTitle', macro, '3 * 3', 9);

## Typing [`t.context`](../01-writing-tests.md#test-context)

By default, the type of `t.context` will be the empty object (`{}`). AVA exposes an interface `TestInterface<Context>` which you can use to apply your own type to `t.context`. This can help you catch errors at compile-time:
By default, the type of `t.context` will be the empty object (`{}`). AVA exposes an interface `TestInterface<Context>` (in AVA 4 this is `TestFn<Context>`) which you can use to apply your own type to `t.context`. This can help you catch errors at compile-time:

```ts
import anyTest, {TestInterface} from 'ava';
import anyTest, {TestInterface} from 'ava'; // AVA 3
// import anyTest, {TestFn as TestInterface} from 'ava'; // AVA 4, usage is the same

const test = anyTest as TestInterface<{foo: string}>;

Expand All @@ -213,7 +214,7 @@ test('an actual test', t => {
You can also type the context when creating macros:

```ts
import anyTest, {Macro, TestInterface} from 'ava';
import anyTest, {Macro, TestInterface} from 'ava'; // AVA 3

interface Context {
foo: string
Expand Down

0 comments on commit 4b4b2f6

Please sign in to comment.