Skip to content

Commit bd4d366

Browse files
committed
chore(docs): Add overloads documentation
1 parent 53e73f6 commit bd4d366

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

ui/src/views/config.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ We are working on an [issue](https://github.com/Typescript-TDD/ts-auto-mock/issu
5555

5656
---
5757
## Features
58+
5859
We currently support the following features
60+
61+
- Random
62+
- Overloads
63+
5964
### Random ('random')
6065

6166
When adding random to the feature list any string, boolean and number will be transformed to a random values
@@ -92,7 +97,23 @@ interface WithBoolean {
9297
prop: boolean;
9398
}
9499

95-
createMock<WithBoolean>() // { prop: true|false}
100+
createMock<WithBoolean>() // { prop: true | false }
96101
```
97102

98-
true|false will be random
103+
`true | false` will be random
104+
105+
### Overloads ('overloads')
106+
107+
By default, the `ts-auto-mock` transformer will pick the very first signature of whatever function it comes by. Enabling the overloads feature will make the transformer consider overloaded- functions and interface call signatures and emit additional logic in order to select the correct mock at runtime. It utilizes the information the type checker provides and attaches it to the context of a function call which is then used to determine the mocked return value using a lazy jump table, thereby only evaluating those values on-demand.
108+
109+
The expected behavior (type-wise) is to have this feature enabled, but do note it emits additional code that may affect performance.
110+
111+
Example:
112+
```ts
113+
declare function overloadedFunction(a: string): boolean;
114+
declare function overloadedFunction(a: boolean): string;
115+
116+
const func = createMock<typeof overloadedFunction>();
117+
func(''); // Returns false
118+
func(false); // Returns ''
119+
```

0 commit comments

Comments
 (0)