Skip to content

Commit a7a301b

Browse files
committed
Changed solution to 32
1 parent 3f418fc commit a7a301b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/07-challenges/32-narrow-with-arrays.solution.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { F } from "ts-toolbelt";
21
import { Equal, Expect } from "../helpers/type-utils";
2+
import { F } from "ts-toolbelt";
33

44
interface Fruit {
55
name: string;
66
price: number;
77
}
88

99
export const wrapFruit = <TFruits extends Fruit[]>(
10-
fruits: F.Narrow<TFruits>,
10+
fruits: F.Narrow<TFruits>
1111
) => {
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+
>;
1617
};
1718

1819
return {
@@ -38,5 +39,5 @@ const notAllowed = fruits.getFruit("not-allowed");
3839

3940
type tests = [
4041
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 }>>
4243
];

0 commit comments

Comments
 (0)