Skip to content

Commit 271d90a

Browse files
committed
Improve TypeScript idioms
1 parent 4417bce commit 271d90a

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

components/FilterBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import { hasAllKeys, SortOptionKey, SortOptions } from "lib/sorting";
1919
import { ReactNode } from "react";
2020
import { atom, useRecoilState, useRecoilValue } from "recoil";
2121

22-
interface FilterState {
22+
type FilterState = {
2323
sort: SortOptionKey;
2424
framework: FrameworkName | null;
2525
features: Set<FeatureName>;
2626
license: string | null;
27-
}
27+
};
2828

2929
const filterState = atom<FilterState>({
3030
key: "filters",

components/MultiItemPicker.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ import { GoChevronDown } from "react-icons/go";
1515
// We use "T extends string" instead of string because we want to be able to
1616
// limit the strings that can be used as keys, such as with FeatureName.
1717

18-
interface Option<T extends string> {
18+
type Option<T extends string> = {
1919
key: T;
2020
title: string;
2121
description: string;
22-
}
22+
};
2323

24-
interface MultiItemPickerProps<T extends string> {
24+
type MultiItemPickerProps<T extends string> = {
2525
children: ReactNode;
2626
selected: Set<T>;
2727
options: Option<T>[];
2828
onChange: (newValue: Set<T>) => void;
29-
}
29+
};
3030

3131
export const MultiItemPicker = <T extends string>({
3232
children,

components/SingleItemPicker.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ import {
1010
import React, { ReactNode } from "react";
1111
import { GoCheck, GoChevronDown } from "react-icons/go";
1212

13-
interface Option {
13+
type Option = {
1414
key: string;
1515
title: string;
1616
description?: string;
17-
}
17+
};
1818

1919
const BlankIcon = () => <Box boxSize="1em" />;
2020

21-
interface Props {
21+
type SingleItemPickerProps = {
2222
children: ReactNode;
2323
selected: string | null;
2424
options: Option[];
2525
allowNull?: boolean;
2626
onChange: (newValue: any) => void;
27-
}
27+
};
2828

2929
export const SingleItemPicker = ({
3030
children,
3131
selected,
3232
options,
3333
onChange,
3434
allowNull = true,
35-
}: Props) => {
35+
}: SingleItemPickerProps) => {
3636
return (
3737
<Menu>
3838
<MenuButton as={Button} rightIcon={<GoChevronDown />} fontWeight="normal">

lib/sorting.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { FeatureName } from "./features";
22
import { LibraryInfo } from "./libraries";
33

4-
export interface SortOption {
4+
export type SortOption = {
55
key: "popularity" | "stars" | "downloads";
66
title: string;
77
description?: string;
88
fn: (a: LibraryInfo, b: LibraryInfo) => number;
9-
}
9+
};
1010

1111
export type SortOptionKey = SortOption["key"];
1212
export const SortOptions: SortOption[] = [
@@ -35,7 +35,7 @@ export const SortOptions: SortOption[] = [
3535
// Sort the features by negative ones first, then positive, then middling.
3636
// Only important negative features are shown, which is why they're first.
3737
export const sortedFeatureNames = (
38-
features: LibraryInfo["features"]
38+
features: LibraryInfo["features"],
3939
): FeatureName[] =>
4040
Object.keys(features).sort((a, b) => {
4141
const av = features[a];

pages/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import GithubCorner from "react-github-corner";
1717
import { DateTime } from "luxon";
1818
import { FaExternalLinkAlt } from "react-icons/fa";
1919

20-
interface Props {
20+
type PageProps = {
2121
items: LibraryInfo[];
2222
ts: string;
23-
}
23+
};
2424

2525
export const getStaticProps: GetStaticProps = async () => {
2626
return {
@@ -31,7 +31,7 @@ export const getStaticProps: GetStaticProps = async () => {
3131
};
3232
};
3333

34-
const Page: NextPage<Props> = ({ items, ts }) => (
34+
const Page: NextPage<PageProps> = ({ items, ts }) => (
3535
<>
3636
<Head>
3737
<title>

pages/list.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import {
1212
import { getLibraries, LibraryInfo } from "lib/libraries";
1313
import { GetStaticProps, NextPage } from "next";
1414

15-
interface Props {
15+
type PageProps = {
1616
items: LibraryInfo[];
17-
}
17+
};
1818

1919
const LinkTo = ({ href }: { href?: string | null }) =>
2020
href ? <Link href={href}>Link</Link> : <span />;
2121

22-
const Page: NextPage<Props> = ({ items }) => (
22+
const Page: NextPage<PageProps> = ({ items }) => (
2323
<Container maxW="full">
2424
<Heading>All Libraries</Heading>
2525
<Table size="sm">

0 commit comments

Comments
 (0)