8000 Added info in the readme about new equals functions · SebastienGllmt/typescript-is@c108790 · GitHub
[go: up one dir, main page]

Skip to content

Commit c108790

Browse files
committed
Added info in the readme about new equals functions
1 parent 0304f0d commit c108790

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ new A().method(42) === 42; // true
216216
new A().method('42' as any); // will throw error
217217
```
218218

219+
## Strict equality (`equals`, `createEquals`, `assertEquals`, `createAssertEquals`)
220+
221+
This family of functions check not only whether the passed object is assignable to the specified type, but also checks that the passed object does not contain any more than is necessary. In other words: the type is also "assignable" to the object. This functionality is equivalent to specifying `disallowSuperfluousObjectProperties` in the options, the difference is that this will apply only to the specific function call. For example:
222+
223+
```typescript
224+
import { equals } from 'typescript-is';
225+
226+
interface X {
227+
x: string;
228+
}
229+
230+
equals<X>({}); // false, because `x` is missing
231+
equals<X>({ x: 'value' }); // true
232+
equals<X>({ x: 'value', y: 'another value' }); // false, because `y` is superfluous
233+
```
234+
219235
To see the declarations of the functions and more examples, please check out [index.d.ts](https://github.com/woutervh-/typescript-is/blob/master/index.d.ts).
220236

221237
For **many more examples**, please check out the files in the [test/](https://github.com/woutervh-/typescript-is/tree/master/test) folder.

0 commit comments

Comments
 (0)
0