Skip to content

Commit 45bad74

Browse files
committed
Fix TypeScript strict mode kinda
1 parent db3377c commit 45bad74

12 files changed

+59
-27
lines changed

components/Card.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
useColorModeValue,
1414
} from "@chakra-ui/react"
1515
import { fileSize } from "humanize-plus"
16-
import { Features } from "lib/features"
16+
import { FeatureName, Features } from "lib/features"
1717
import { FrameworkIcons, FrameworkTitles } from "lib/frameworks"
18-
import { LibraryInfo } from "lib/libraries"
18+
import { FrameworkName, LibraryInfo } from "lib/libraries"
1919
import { sortedFeatureNames } from "lib/sorting"
2020
import { JSXElementConstructor } from "react"
2121
import {
@@ -49,7 +49,7 @@ const ColoredIcon = ({
4949
const useCardBackgroundColor = () => useColorModeValue("white", "gray.700")
5050

5151
const Feature: React.FC<{
52-
name: string
52+
name: FeatureName
5353
value: boolean | string | null
5454
}> = ({ name, value }) => {
5555
if (!Features[name]) {
@@ -85,9 +85,10 @@ const Feature: React.FC<{
8585

8686
const FrameworkList: React.FC<{ info: LibraryInfo }> = ({ info }) => {
8787
const bg = useCardBackgroundColor()
88+
const names = Object.keys(info.frameworks) as FrameworkName[]
8889
return (
8990
<Flex fontSize="2xl">
90-
{Object.keys(info.frameworks).map((name) => {
91+
{names.map((name) => {
9192
const value = info.frameworks[name]
9293
const isThirdParty = typeof value === "string"
9394
const url = isThirdParty ? value : info.homeUrl
@@ -98,7 +99,7 @@ const FrameworkList: React.FC<{ info: LibraryInfo }> = ({ info }) => {
9899
return (
99100
<Tooltip label={title} key={name}>
100101
<Link
101-
href={url}
102+
href={url ?? undefined}
102103
position="relative"
103104
_hover={{ opacity: 0.75 }}
104105
title={title}
@@ -176,7 +177,7 @@ const Card: React.FC<{ info: LibraryInfo }> = ({ info }) => {
176177
<Heading
177178
size="lg"
178179
as="a"
179-
href={info.homeUrl}
180+
href={info.homeUrl ?? undefined}
180181
fontWeight="semibold"
181182
id={id}
182183
>

components/FilterBar.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const ResponsiveText = ({ short, long }: { short: string; long: string }) => (
2222
)
2323

2424
const FrameworkSelector: React.FC<{
25-
selected: FrameworkName
26-
onChange: (newSelected: FrameworkName) => void
25+
selected: FrameworkName | null
26+
onChange: (newSelected: FrameworkName | null) => void
2727
}> = ({ selected, onChange }) => {
2828
const handleToggle = (name: FrameworkName) => () => {
2929
onChange(selected === name ? null : name)
@@ -107,7 +107,7 @@ const SortSelector: React.FC<{
107107
options={SortOptions}
108108
allowNull={false}
109109
>
110-
<ResponsiveText short="Sort" long={`Sort by ${selectedOption.title}`} />
110+
<ResponsiveText short="Sort" long={`Sort by ${selectedOption?.title}`} />
111111
</SingleItemPicker>
112112
)
113113
}
@@ -137,7 +137,9 @@ const FilterBar: React.FC<FilteredItemsProps> = ({ items, children }) => {
137137
clone.sort(sortOption.fn)
138138

139139
if (filters.framework) {
140-
clone = clone.filter((item) => item.frameworks[filters.framework])
140+
clone = clone.filter(
141+
(item) => filters.framework && item.frameworks[filters.framework]
142+
)
141143
}
142144
if (filters.features.size) {
143145
clone = clone.filter((item) => hasAllKeys(item.features, filters.features))
@@ -174,7 +176,7 @@ const FilterBar: React.FC<FilteredItemsProps> = ({ items, children }) => {
174176
}}
175177
/>
176178
<LicenseSelector
177-
licenses={new Set(items.map((i) => i.license))}
179+
licenses={new Set<string>(items.map((i: any) => i.license))}
178180
selected={filters.license}
179181
onChange={(license) => {
180182
setFilters({ ...filters, license })

components/MultiItemPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface Option {
2121
export const MultiItemPicker: React.FC<{
2222
selected: Set<string>
2323
options: Option[]
24-
onChange: (newValue: Set<string>) => void
24+
onChange: (newValue: any) => void
2525
}> = ({ children, selected, options, onChange }) => (
2626
<Menu>
2727
<MenuButton as={Button} rightIcon={<GoChevronDown />} fontWeight="normal">

components/SingleItemPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const SingleItemPicker: React.FC<{
2222
selected: string | null
2323
options: Option[]
2424
allowNull?: boolean
25-
onChange: (newValue: string) => void
25+
onChange: (newValue: any) => void
2626
}> = ({ children, selected, options, onChange, allowNull = true }) => {
2727
return (
2828
<Menu>

lib/features.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,81 @@ export const Features = {
88
title: "Accessible",
99
description:
1010
"Uses semantic markup or ARIA attributes to make the interface less challenging to use.",
11+
important: false,
1112
},
1213
copyPaste: {
1314
title: "Copy and Paste",
1415
description: "Supports copy and paste, preferably to the system clipboard.",
16+
important: false,
1517
},
1618
csvExport: {
1719
title: "CSV Export",
1820
description:
1921
"The library has built-in functionality which lets you download a CSV file.",
22+
important: false,
2023
},
2124
customEditors: {
2225
title: "Custom Editors",
2326
description:
2427
"The library lets you create your own dynamic cell value editor widgets.",
28+
important: false,
2529
},
2630
customFormatters: {
2731
title: "Custom Formatters",
2832
description:
2933
"The library lets you customize how data is shown in each grid cell.",
34+
important: false,
3035
},
3136
draggableRows: {
3237
title: "Draggable Rows",
3338
description: "Allows rows to be reordered by dragging.",
39+
important: false,
3440
},
3541
editable: {
3642
title: "Editable Cells",
3743
description: "Cell values can be changed to update data in memory.",
44+
important: false,
3845
},
3946
fillDown: {
4047
title: "Fill Down",
4148
description:
4249
"A drag handle or keyboard shortcut can be used to copy a value or formula to cells below the selected cell.",
50+
important: false,
4351
},
4452
fillRight: {
4553
title: "Fill Right",
4654
description:
4755
"A drag handle or keyboard shortcut can be used to copy a value or formula to cells to the right of the selected cell.",
56+
important: false,
4857
},
4958
filtering: {
5059
title: "Filtering",
5160
description:
5261
"The library or interface has provisions for only showing rows that meet certain criteria.",
62+
important: false,
5363
},
5464
formulas: {
5565
title: "Formula Support",
5666
description:
5767
"The library has built-in support for deriving cell values from other cells.",
68+
important: false,
5869
},
5970
freezableCols: {
6071
title: "Freezable Columns",
6172
description:
6273
"The library lets you make columns persist on one or both sides of the grid.",
74+
important: false,
6375
},
6476
headless: {
6577
title: "Headless",
6678
description:
6779
"There is no user interface provided by default; this library is logic-only.",
80+
important: false,
6881
},
6982
i18n: {
7083
title: "i18n",
7184
description: "Has features for internationalization and localization.",
85+
important: false,
7286
},
7387
maintained: {
7488
title: "Maintained",
@@ -86,62 +100,75 @@ export const Features = {
86100
title: "Pagination",
87101
description:
88102
"Supports a widget to navigate through pages of rows as opposed to scrolling.",
103+
important: false,
89104
},
90105
pdfExport: {
91106
title: "PDF Export",
92107
description:
93108
"The library has built-in functionality which lets you download a PDF.",
109+
important: false,
94110
},
95111
pivots: {
96112
title: "Pivot Tables",
97113
description: "Has support for pivot tables.",
114+
important: false,
98115
},
99116
rangeSelection: {
100117
title: "Range Selection",
101118
description: "An arbitrary block of cells can be selected.",
119+
important: false,
102120
},
103121
resizableCols: {
104122
title: "Resizable Columns",
105123
description: "The user interface lets you resize columns by dragging.",
124+
important: false,
106125
},
107126
responsive: {
108127
title: "Responsive",
109128
description: "Works well on tablet and mobile devices.",
129+
important: false,
110130
},
111131
rowGrouping: {
112132
title: "Row Grouping",
113133
description:
114134
"Whether rows be grouped and preferably collapsed and expanded.",
135+
important: false,
115136
},
116137
rowSelection: {
117138
title: "Row Selection",
118139
description: "Entire rows can be selected.",
140+
important: false,
119141
},
120142
serverSide: {
121143
title: "Server-Side",
122144
description:
123145
"Has the ability to use external data sources to fetch, filter, and sort data.",
146+
important: false,
124147
},
125148
sorting: {
126149
title: "Sorting",
127150
description:
128151
"The library or interface has provisions for ordering rows given certain criteria.",
152+
important: false,
129153
},
130154
trees: {
131155
title: "Tree Data",
132156
description: "Has support for hierarchical data.",
157+
important: false,
133158
},
134159
xlsxExport: {
135160
title: "XLSX Export",
136161
description:
137162
"The library has built-in functionality which lets you download an Excel workbook.",
163+
important: false,
138164
},
139165
virtualization: {
140166
title: "Virtualization",
141167
description:
142168
"Uses a technique to greatly reduce DOM elements and increase performance.",
169+
important: false,
143170
},
144-
}
171+
} as const
145172

146173
export type FeatureName = keyof typeof Features
147174

lib/fetcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const throttledFetch = throttler(async (url: string) => {
4040
const res = await fetch(url, { headers })
4141
const data = await res.json()
4242
return { headers: JSON.parse(JSON.stringify(res.headers)), data }
43-
} catch (err) {
43+
} catch (err: any) {
4444
const status = err.response?.status
4545
const headers = JSON.stringify(err.response?.headers, null, " ")
4646
log("failed %s - status=%s, headers=%o - %s", url, status, headers, err)

lib/libraries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const getLibraries = async (): Promise<LibraryInfo[]> => {
152152
} else {
153153
const link = res1.headers.link ?? ""
154154
const parts = link.split(",")
155-
const lastPart = parts.find((s) => /rel="last"/.test(s)) ?? ""
155+
const lastPart = parts.find((s: string) => /rel="last"/.test(s)) ?? ""
156156
const match = lastPart.match(/\bpage=(\d+)/)
157157
const lastPage = Number(match ? match[1] : 1)
158158
const res2 = await fetcher(`${url}&page=${lastPage}`)

lib/sorting.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FeatureName } from "./features"
12
import { LibraryInfo } from "./libraries"
23

34
export interface SortOption {
@@ -35,7 +36,7 @@ export const SortOptions: SortOption[] = [
3536
// Only important negative features are shown, which is why they're first.
3637
export const sortedFeatureNames = (
3738
features: LibraryInfo["features"]
38-
): string[] =>
39+
): FeatureName[] =>
3940
Object.keys(features).sort((a, b) => {
4041
const av = features[a]
4142
const bv = features[b]
@@ -54,9 +55,9 @@ export const sortedFeatureNames = (
5455
} else {
5556
return a.localeCompare(b)
5657
}
57-
})
58+
}) as FeatureName[]
5859

59-
export const hasAllKeys = (obj: Object, keys: Iterable<string>) => {
60+
export const hasAllKeys = (obj: any, keys: Iterable<string>) => {
6061
for (const key of Array.from(keys)) {
6162
if (!obj[key]) {
6263
return false

lib/theme.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const theme = extendTheme({
77
useSystemColorMode: false,
88
},
99
styles: {
10-
global: (props) => ({
10+
global: (props: any) => ({
1111
body: {
1212
bg: mode("gray.100", "gray.800")(props),
1313
color: mode("gray.900", "gray.100")(props),

pages/_app.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ChakraProvider } from "@chakra-ui/react"
22
import theme from "lib/theme"
33
import { DefaultSeo } from "next-seo"
4+
import { AppProps } from "next/app"
45

5-
function MyApp({ Component, pageProps }) {
6+
function MyApp({ Component, pageProps }: AppProps) {
67
return (
78
<ChakraProvider theme={theme}>
89
<DefaultSeo

pages/list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Props {
1818
items: LibraryInfo[]
1919
}
2020

21-
const LinkTo = ({ href }: { href?: string }) =>
21+
const LinkTo = ({ href }: { href?: string | null }) =>
2222
href ? <Link href={href}>Link</Link> : <span />
2323

2424
const Page: NextPage<Props> = ({ items }) => (

tsconfig.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4-
"strict": false,
54
"target": "es5",
65
"lib": ["dom", "dom.iterable", "esnext"],
76
"allowJs": true,
87
"skipLibCheck": true,
8+
"strict": true,
99
"forceConsistentCasingInFileNames": true,
1010
"noEmit": true,
11+
"incremental": true,
1112
"esModuleInterop": true,
1213
"module": "esnext",
1314
"moduleResolution": "node",
1415
"resolveJsonModule": true,
1516
"isolatedModules": true,
16-
"jsx": "preserve",
17-
"incremental": true
17+
"jsx": "preserve"
1818
},
19-
"exclude": ["node_modules"],
20-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
19+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
20+
"exclude": ["node_modules"]
2121
}

0 commit comments

Comments
 (0)