tstyche 1.0.0 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![version][version-badge]][version-url]
4
4
  [![license][license-badge]][license-url]
5
- [![packagephobia][packagephobia-badge]][packagephobia-url]
5
+ [![requirements][requirements-badge]][requirements-url]
6
+ [![install-size][install-size-badge]][install-size-url]
6
7
  [![coverage][coverage-badge]][coverage-url]
7
8
  [![discord][discord-badge]][discord-url]
8
9
 
@@ -24,7 +25,7 @@ function firstItem<T>(target: Array<T>): T | undefined {
24
25
  }
25
26
 
26
27
  test("firstItem", () => {
27
- expect(firstItem(["a", "b", "c"])).type.toEqual<string | undefined>();
28
+ expect(firstItem(["a", "b", "c"])).type.toBe<string | undefined>();
28
29
 
29
30
  expect(firstItem()).type.toRaiseError("Expected 1 argument");
30
31
  });
@@ -51,13 +52,13 @@ function secondItem<T>(target: Array<T>): T | undefined {
51
52
  test("handles numbers", () => {
52
53
  assert.strictEqual(secondItem([1, 2, 3]), 2);
53
54
 
54
- tstyche.expect(secondItem([1, 2, 3])).type.toEqual<number | undefined>();
55
+ tstyche.expect(secondItem([1, 2, 3])).type.toBe<number | undefined>();
55
56
  });
56
57
  ```
57
58
 
58
59
  Here is the list of all matchers:
59
60
 
60
- - `.toBeAssignable()`, `.toEqual()`, `.toMatch()` compares types or types of expression,
61
+ - `.toBe()`, `.toBeAssignableTo()`, `.toBeAssignableWith()`, `.toMatch()` compare types or types of expression,
61
62
  - `.toHaveProperty()` looks up keys on an object type,
62
63
  - `.toRaiseError()` captures the type error message or code,
63
64
  - `.toBeString()`, `.toBeNumber()`, `.toBeVoid()` and 9 more shorthand checks for primitive types.
@@ -88,8 +89,10 @@ If you have any questions or suggestions, [start a discussion](https://github.co
88
89
  [version-url]: https://npmjs.com/package/tstyche
89
90
  [license-badge]: https://badgen.net/github/license/tstyche/tstyche
90
91
  [license-url]: https://github.com/tstyche/tstyche/blob/main/LICENSE.md
91
- [packagephobia-badge]: https://badgen.net/packagephobia/install/tstyche
92
- [packagephobia-url]: https://packagephobia.com/result?p=tstyche
92
+ [requirements-badge]: https://badgen.net/npm/node/tstyche
93
+ [requirements-url]: https://tstyche.org/reference/requirements
94
+ [install-size-badge]: https://badgen.net/packagephobia/install/tstyche
95
+ [install-size-url]: https://packagephobia.com/result?p=tstyche
93
96
  [coverage-badge]: https://badgen.net/codacy/coverage/a581ca5c323a455886b7bdd9623c4ec8
94
97
  [coverage-url]: https://app.codacy.com/gh/tstyche/tstyche/coverage/dashboard
95
98
  [discord-badge]: https://badgen.net/static/chat/on%20Discord
package/build/index.d.cts CHANGED
@@ -60,100 +60,159 @@ interface Test {
60
60
  }
61
61
  interface Matchers {
62
62
  /**
63
- * Checks if the `any` type is identical to the source type.
63
+ * Checks if the source type is identical to the target type.
64
64
  */
65
- toBeAny: () => void;
65
+ toBe: {
66
+ /**
67
+ * Checks if the source type is identical to the target type.
68
+ */
69
+ <Target>(): void;
70
+ /**
71
+ * Checks if the source type is identical to type of the target expression.
72
+ */
73
+ (target: unknown): void;
74
+ };
66
75
  /**
67
- * Checks if the target type is assignable to the source type.
76
+ * Checks if the source type is assignable with the target type.
77
+ *
78
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
79
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
68
80
  */
69
81
  toBeAssignable: {
70
82
  /**
71
- * Checks if the target type is assignable to the source type.
83
+ * Checks if the source type is assignable with the target type.
84
+ *
85
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
86
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
87
+ */
88
+ <Target>(): void;
89
+ /**
90
+ * Checks if the source type is assignable with type of the target expression.
91
+ *
92
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
93
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
94
+ */
95
+ (target: unknown): void;
96
+ };
97
+ /**
98
+ * Checks if the source type is assignable to the target type.
99
+ */
100
+ toBeAssignableTo: {
101
+ /**
102
+ * Checks if the source type is assignable to the target type.
72
103
  */
73
104
  <Target>(): void;
74
105
  /**
75
- * Checks if type of the target expression is assignable to the source type.
106
+ * Checks if the source type is assignable to type of the target expression.
76
107
  */
77
108
  (target: unknown): void;
78
109
  };
79
110
  /**
80
- * Checks if the `bigint` type is identical to the source type.
111
+ * Checks if the source type is assignable with the target type.
112
+ */
113
+ toBeAssignableWith: {
114
+ /**
115
+ * Checks if the source type is assignable with the target type.
116
+ */
117
+ <Target>(): void;
118
+ /**
119
+ * Checks if the source type is assignable with type of the target expression.
120
+ */
121
+ (target: unknown): void;
122
+ };
123
+ /**
124
+ * Checks if the source type is identical to the target type.
125
+ *
126
+ * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
127
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
128
+ */
129
+ toEqual: {
130
+ /**
131
+ * Checks if the source type is identical to the target type.
132
+ *
133
+ * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
134
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
135
+ */
136
+ <Target>(): void;
137
+ /**
138
+ * Checks if the source type is identical to type of the target expression.
139
+ *
140
+ * @deprecated This matcher will be removed in TSTyche 3.
141
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
142
+ */
143
+ (target: unknown): void;
144
+ };
145
+ /**
146
+ * Checks if a property key exists on the source type.
147
+ */
148
+ toHaveProperty: (key: string | number | symbol) => void;
149
+ /**
150
+ * Checks if the source type matches the target type.
151
+ */
152
+ toMatch: {
153
+ /**
154
+ * Checks if the source type matches the target type.
155
+ */
156
+ <Target>(): void;
157
+ /**
158
+ * Checks if the source type matches type of the target expression.
159
+ */
160
+ (target: unknown): void;
161
+ };
162
+ /**
163
+ * Checks if the source type raises an error.
164
+ */
165
+ toRaiseError: (...target: Array<string | number>) => void;
166
+ }
167
+ interface Matchers {
168
+ /**
169
+ * Checks if the source type is `any`.
170
+ */
171
+ toBeAny: () => void;
172
+ /**
173
+ * Checks if the source type is `bigint`.
81
174
  */
82
175
  toBeBigInt: () => void;
83
176
  /**
84
- * Checks if the `boolean` type is identical to the source type.
177
+ * Checks if the source type is `boolean`.
85
178
  */
86
179
  toBeBoolean: () => void;
87
180
  /**
88
- * Checks if the `never` type is identical to the source type.
181
+ * Checks if the source type is `never`.
89
182
  */
90
183
  toBeNever: () => void;
91
184
  /**
92
- * Checks if the `null` type is identical to the source type.
185
+ * Checks if the source type is `null`.
93
186
  */
94
187
  toBeNull: () => void;
95
188
  /**
96
- * Checks if the `number` type is identical to the source type.
189
+ * Checks if the source type is `number`.
97
190
  */
98
191
  toBeNumber: () => void;
99
192
  /**
100
- * Checks if the `string` type is identical to the source type.
193
+ * Checks if the source type is `string`.
101
194
  */
102
195
  toBeString: () => void;
103
196
  /**
104
- * Checks if the `symbol` type is identical to the source type.
197
+ * Checks if the source type is `symbol`.
105
198
  */
106
199
  toBeSymbol: () => void;
107
200
  /**
108
- * Checks if the `undefined` type is identical to the source type.
201
+ * Checks if the source type is `undefined`.
109
202
  */
110
203
  toBeUndefined: () => void;
111
204
  /**
112
- * Checks if the `unique symbol` type is identical to the source type.
205
+ * Checks if the source type is `unique symbol`.
113
206
  */
114
207
  toBeUniqueSymbol: () => void;
115
208
  /**
116
- * Checks if the `unknown` type is identical to the source type.
209
+ * Checks if the source type is `unknown`.
117
210
  */
118
211
  toBeUnknown: () => void;
119
212
  /**
120
- * Checks if the `void` type is identical to the source type.
213
+ * Checks if the source type is `void`.
121
214
  */
122
215
  toBeVoid: () => void;
123
- /**
124
- * Check if the target type is identical to the source type.
125
- */
126
- toEqual: {
127
- /**
128
- * Checks if the target type is identical to the source type.
129
- */
130
- <Target>(): void;
131
- /**
132
- * Checks if type of the target expression is identical to the source type.
133
- */
134
- (target: unknown): void;
135
- };
136
- /**
137
- * Checks if a property key exists on the source type.
138
- */
139
- toHaveProperty: (key: string | number | symbol) => void;
140
- /**
141
- * Checks if the target type is a subtype the source type.
142
- */
143
- toMatch: {
144
- /**
145
- * Checks if the target type is a subtype the source type.
146
- */
147
- <Target>(): void;
148
- /**
149
- * Checks if type of the target expression is a subtype the source type.
150
- */
151
- (target: unknown): void;
152
- };
153
- /**
154
- * Checks if the source type raises an error.
155
- */
156
- toRaiseError: (...target: Array<string | number>) => void;
157
216
  }
158
217
  interface Modifier {
159
218
  /**
package/build/index.d.ts CHANGED
@@ -60,100 +60,159 @@ interface Test {
60
60
  }
61
61
  interface Matchers {
62
62
  /**
63
- * Checks if the `any` type is identical to the source type.
63
+ * Checks if the source type is identical to the target type.
64
64
  */
65
- toBeAny: () => void;
65
+ toBe: {
66
+ /**
67
+ * Checks if the source type is identical to the target type.
68
+ */
69
+ <Target>(): void;
70
+ /**
71
+ * Checks if the source type is identical to type of the target expression.
72
+ */
73
+ (target: unknown): void;
74
+ };
66
75
  /**
67
- * Checks if the target type is assignable to the source type.
76
+ * Checks if the source type is assignable with the target type.
77
+ *
78
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
79
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
68
80
  */
69
81
  toBeAssignable: {
70
82
  /**
71
- * Checks if the target type is assignable to the source type.
83
+ * Checks if the source type is assignable with the target type.
84
+ *
85
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
86
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
87
+ */
88
+ <Target>(): void;
89
+ /**
90
+ * Checks if the source type is assignable with type of the target expression.
91
+ *
92
+ * @deprecated Use `.toBeAssignableWith()` or `.toBeAssignableTo()` instead. This matcher will be removed in TSTyche 3.
93
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
94
+ */
95
+ (target: unknown): void;
96
+ };
97
+ /**
98
+ * Checks if the source type is assignable to the target type.
99
+ */
100
+ toBeAssignableTo: {
101
+ /**
102
+ * Checks if the source type is assignable to the target type.
72
103
  */
73
104
  <Target>(): void;
74
105
  /**
75
- * Checks if type of the target expression is assignable to the source type.
106
+ * Checks if the source type is assignable to type of the target expression.
76
107
  */
77
108
  (target: unknown): void;
78
109
  };
79
110
  /**
80
- * Checks if the `bigint` type is identical to the source type.
111
+ * Checks if the source type is assignable with the target type.
112
+ */
113
+ toBeAssignableWith: {
114
+ /**
115
+ * Checks if the source type is assignable with the target type.
116
+ */
117
+ <Target>(): void;
118
+ /**
119
+ * Checks if the source type is assignable with type of the target expression.
120
+ */
121
+ (target: unknown): void;
122
+ };
123
+ /**
124
+ * Checks if the source type is identical to the target type.
125
+ *
126
+ * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
127
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
128
+ */
129
+ toEqual: {
130
+ /**
131
+ * Checks if the source type is identical to the target type.
132
+ *
133
+ * @deprecated Use `.toBe()` instead. This matcher will be removed in TSTyche 3.
134
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
135
+ */
136
+ <Target>(): void;
137
+ /**
138
+ * Checks if the source type is identical to type of the target expression.
139
+ *
140
+ * @deprecated This matcher will be removed in TSTyche 3.
141
+ * To learn more, visit https://tstyche.org/release-notes/tstyche-2.
142
+ */
143
+ (target: unknown): void;
144
+ };
145
+ /**
146
+ * Checks if a property key exists on the source type.
147
+ */
148
+ toHaveProperty: (key: string | number | symbol) => void;
149
+ /**
150
+ * Checks if the source type matches the target type.
151
+ */
152
+ toMatch: {
153
+ /**
154
+ * Checks if the source type matches the target type.
155
+ */
156
+ <Target>(): void;
157
+ /**
158
+ * Checks if the source type matches type of the target expression.
159
+ */
160
+ (target: unknown): void;
161
+ };
162
+ /**
163
+ * Checks if the source type raises an error.
164
+ */
165
+ toRaiseError: (...target: Array<string | number>) => void;
166
+ }
167
+ interface Matchers {
168
+ /**
169
+ * Checks if the source type is `any`.
170
+ */
171
+ toBeAny: () => void;
172
+ /**
173
+ * Checks if the source type is `bigint`.
81
174
  */
82
175
  toBeBigInt: () => void;
83
176
  /**
84
- * Checks if the `boolean` type is identical to the source type.
177
+ * Checks if the source type is `boolean`.
85
178
  */
86
179
  toBeBoolean: () => void;
87
180
  /**
88
- * Checks if the `never` type is identical to the source type.
181
+ * Checks if the source type is `never`.
89
182
  */
90
183
  toBeNever: () => void;
91
184
  /**
92
- * Checks if the `null` type is identical to the source type.
185
+ * Checks if the source type is `null`.
93
186
  */
94
187
  toBeNull: () => void;
95
188
  /**
96
- * Checks if the `number` type is identical to the source type.
189
+ * Checks if the source type is `number`.
97
190
  */
98
191
  toBeNumber: () => void;
99
192
  /**
100
- * Checks if the `string` type is identical to the source type.
193
+ * Checks if the source type is `string`.
101
194
  */
102
195
  toBeString: () => void;
103
196
  /**
104
- * Checks if the `symbol` type is identical to the source type.
197
+ * Checks if the source type is `symbol`.
105
198
  */
106
199
  toBeSymbol: () => void;
107
200
  /**
108
- * Checks if the `undefined` type is identical to the source type.
201
+ * Checks if the source type is `undefined`.
109
202
  */
110
203
  toBeUndefined: () => void;
111
204
  /**
112
- * Checks if the `unique symbol` type is identical to the source type.
205
+ * Checks if the source type is `unique symbol`.
113
206
  */
114
207
  toBeUniqueSymbol: () => void;
115
208
  /**
116
- * Checks if the `unknown` type is identical to the source type.
209
+ * Checks if the source type is `unknown`.
117
210
  */
118
211
  toBeUnknown: () => void;
119
212
  /**
120
- * Checks if the `void` type is identical to the source type.
213
+ * Checks if the source type is `void`.
121
214
  */
122
215
  toBeVoid: () => void;
123
- /**
124
- * Check if the target type is identical to the source type.
125
- */
126
- toEqual: {
127
- /**
128
- * Checks if the target type is identical to the source type.
129
- */
130
- <Target>(): void;
131
- /**
132
- * Checks if type of the target expression is identical to the source type.
133
- */
134
- (target: unknown): void;
135
- };
136
- /**
137
- * Checks if a property key exists on the source type.
138
- */
139
- toHaveProperty: (key: string | number | symbol) => void;
140
- /**
141
- * Checks if the target type is a subtype the source type.
142
- */
143
- toMatch: {
144
- /**
145
- * Checks if the target type is a subtype the source type.
146
- */
147
- <Target>(): void;
148
- /**
149
- * Checks if type of the target expression is a subtype the source type.
150
- */
151
- (target: unknown): void;
152
- };
153
- /**
154
- * Checks if the source type raises an error.
155
- */
156
- toRaiseError: (...target: Array<string | number>) => void;
157
216
  }
158
217
  interface Modifier {
159
218
  /**