File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 1
- import { F } from "ts-toolbelt" ;
2
1
import { Equal , Expect } from "../helpers/type-utils" ;
2
+ import { F } from "ts-toolbelt" ;
3
3
4
4
interface Fruit {
5
5
name : string ;
6
6
price : number ;
7
7
}
8
8
9
9
export const wrapFruit = < TFruits extends Fruit [ ] > (
10
- fruits : F . Narrow < TFruits > ,
10
+ fruits : F . Narrow < TFruits >
11
11
) => {
12
- const getFruit = < TName extends TFruits [ number ] [ "name" ] > (
13
- name : TName ,
14
- ) : Extract < TFruits [ number ] , { name : TName } > => {
15
- return fruits . find ( ( fruit ) => fruit . name === name ) as any ;
12
+ const getFruit = < TName extends TFruits [ number ] [ "name" ] > ( name : TName ) => {
13
+ return fruits . find ( ( fruit ) => fruit . name === name ) as Extract <
14
+ TFruits [ number ] ,
15
+ { name : TName }
16
+ > ;
16
17
} ;
17
18
18
19
return {
@@ -38,5 +39,5 @@ const notAllowed = fruits.getFruit("not-allowed");
38
39
39
40
type tests = [
40
41
Expect < Equal < typeof apple , { name : "apple" ; price : 1 } > > ,
41
- Expect < Equal < typeof banana , { name : "banana" ; price : 2 } > > ,
42
+ Expect < Equal < typeof banana , { name : "banana" ; price : 2 } > >
42
43
] ;
You can’t perform that action at this time.
0 commit comments