You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The returned type **is guaranted** by the `_check` function.
41
+
The returned type **is guaranted** by the `check` function.
42
42
43
43
# How to use
44
44
@@ -86,7 +86,7 @@ fffunction
86
86
.f<(i: { id:number }) =>Item>()
87
87
.f<(i: { id:number, name:string }) =>Profile>()
88
88
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89
-
// Type 'Profile' does not satisfy the constraint 'never'. ts(2344)
89
+
// Type 'Profile' is not assignable to type 'never'. ts(2344)
90
90
```
91
91
92
92
*Primitive* types **cannot overlap** each others:
@@ -96,7 +96,7 @@ fffunction
96
96
.f<(a:`https://${string}`) =>URL>()
97
97
.f<(a:string) =>string>()
98
98
^^^^^^^^^^^^^^^^^^^^^
99
-
// Type 'string' does not satisfy the constraint 'never'. ts(2344)
99
+
// Type 'string' is not assignable to type 'never'. ts(2344)
100
100
```
101
101
102
102
This ensures that each input type can be **narrowed down** later in the function implementation.
@@ -116,7 +116,7 @@ fffunction
116
116
117
117
This is for two reasons:
118
118
- the inference would only work in "overload mode"
119
-
- the implementation function **cannot check* if the returned value has the proper subset
119
+
- the implementation function **cannot check** if the returned value has the proper subset
120
120
121
121
## Function implementation
122
122
@@ -130,12 +130,12 @@ The implementation of the function is based on the concept of [type narrowing](h
130
130
```
131
131
132
132
The `implementation` function (named here for the example) will receive a tuple. This argument carries:
133
-
- the "check" function that ensures the return value is narrowed down enought
133
+
- the "check" function that ensures the return value is narrowed down enough
134
134
- the argument(s) provided in the same order as declared in the signatures
135
135
136
136
### Narrowing type
137
137
138
-
In the main scope of the function, the type of `arg` is **uncertain**. It can be either of the argument types defined in the signatures. We want to create a narrowed scope for each possible type:
138
+
In the main scope of the function, the type of `arg` is **uncertain**. It can be either of the argument types defined in the signatures. We want to create a narrowed scope for each possible type:
139
139
140
140
```ts
141
141
function implementation ([check, arg]) {
@@ -162,7 +162,7 @@ function implementation ([check, arg]) {
162
162
```
163
163
164
164
> This function is **mandatory**. You can't return any value without using this method.
165
-
> In fact, it must also be called for **void returns**:
165
+
> In fact, it must also be called for **void returns**:
166
166
> ```ts
167
167
>returncheck();
168
168
>```
@@ -180,7 +180,7 @@ fffunction
180
180
if('name'inarg) {
181
181
returncheck('profile');
182
182
^^^^^^^^^
183
-
//Type 'string' does not satisfy the constraint 'never'. ts(2344)
183
+
//Argument of type '"profile"' is not assignable to parameter of type 'never'. ts(2345)
184
184
}
185
185
returncheck('item');
186
186
});
@@ -201,7 +201,7 @@ fffunction
201
201
202
202
### Optional "overload" mode
203
203
204
-
You can enable the **"overload" mode** by passing "overload" to the generic:
204
+
You can enable the **"overload" mode** by passing "overload" to the generic:
205
205
206
206
```ts
207
207
.f<'overload'>(implementation);
@@ -219,7 +219,7 @@ This can make the resulting function easier to understand with each signature in
219
219
220
220
#### Drawback
221
221
222
-
With this approach you loose the ability to call the function with uncertain input data. E.g. the following is not possible:
222
+
With this approach you loose the ability to call the function with uncertain input data. E.g. the following is not possible:
223
223
224
224
```ts
225
225
random(modeas"string"|"number"); // No overload matches this call.
@@ -231,7 +231,7 @@ With the above example, `mode` must be either `"string"` or `"number"`. The unce
231
231
232
232
## Signature declaration
233
233
234
-
### `TS2344: Type 'A' does not satisfy the constraint 'never'`
234
+
### `TS2344: Type 'A' is not assignable to type 'never'`
235
235
236
236
```ts
237
237
.f<(a:"string") =>string>()
@@ -243,7 +243,7 @@ That means input of two signatures are conflicting. See the **input overlapping*
243
243
244
244
## Function implementation
245
245
246
-
### `TS2344: Type 'A' does not satisfy the constraint 'never'`
246
+
### `TS2345: Argument of type 'A' is not assignable to parameter of type 'never'`
0 commit comments