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
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Function parameters are checked one at a time, with the type in each corresponding parameter position checked against each other.
256
256
If you do not want to specify types at all, TypeScript's contextual typing can infer the argument types since the function value is assigned directly to a variable of type `SearchFunc`.
257
257
Here, also, the return type of our function expression is implied by the values it returns (here `false` and `true`).
258
-
Had the function expression returned numbers or strings, the type checker would have warned us that return type doesn't match the return type described in the `SearchFunc` interface.
Had the function expression returned numbers or strings, the type checker would have made an error that indicates return type doesn't match the return type described in the `SearchFunc` interface.
268
+
269
+
```ts
270
+
let mySearch:SearchFunc;
271
+
272
+
// error: Type '(src: string, sub: string) => string' is not assignable to type 'SearchFunc'.
273
+
// Type 'string' is not assignable to type 'boolean'.
274
+
mySearch=function(src, sub) {
275
+
let result =src.search(sub);
276
+
return"string";
277
+
};
278
+
```
279
+
268
280
# Indexable Types
269
281
270
282
Similarly to how we can use interfaces to describe function types, we can also describe types that we can "index into" like `a[10]`, or `ageMap["daniel"]`.
0 commit comments