Skip to content

Commit 5851d54

Browse files
committed
refactor(lint): more strict types (where i could...)
#163
1 parent 48c4a42 commit 5851d54

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

src/features/repo-list/items/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { Empty } from "antd";
33
import { Repo, Card } from "shared/components";
4+
import { VeryMaybe, Repository } from "models";
45
import { RepositoriesDetailsFragment } from "../queries.gen";
56
import { useStarring } from "../hooks";
67

@@ -31,7 +32,7 @@ const RepoListItems = (props: Props) => {
3132
<Repo
3233
onStarring={() => starring.handle(node?.id, node?.viewerHasStarred)}
3334
key={node?.id}
34-
data={node}
35+
data={node as VeryMaybe<Repository>}
3536
loading={starring.debouncedLoadingId === node?.id}
3637
/>
3738
))

src/features/search/results/list/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import cn from "classnames";
33
import { Empty } from "antd";
44
import { Repo, User, Org, Card } from "shared/components";
5+
import { VeryMaybe, Repository } from "models";
56
import { SearchQuery } from "../queries.gen";
67
import "./index.scss";
78

@@ -35,7 +36,9 @@ const ResultsList = (props: Props) => {
3536
className={cn("search-results__item", "mb-6", (node as any).__typename)}
3637
>
3738
{/* !!! FIXME: simplify */}
38-
{isRepoSearch && <Repo data={node} format="owner-repo" />}
39+
{isRepoSearch && (
40+
<Repo data={node as VeryMaybe<Repository>} format="owner-repo" />
41+
)}
3942
{isUserSearch &&
4043
((node as any)?.__typename === "Organization" ? (
4144
<Org data={node} />

src/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ export type GitCommit = {
5151
name?: string | null;
5252
date: string;
5353
};
54+
55+
/**
56+
* Вынужденная обертка для некоторых компонентов по данным с API
57+
* !!! FIXME: more strict types (TotallyNullable not help...) or fix on codegen level
58+
*/
59+
export type VeryMaybe<T> = import("models.gen").Maybe<Partial<T>>;

src/shared/components/org/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import React from "react";
22
import { Button } from "antd";
33
import { BankOutlined } from "@ant-design/icons";
4+
import { VeryMaybe, Organization } from "models";
45
import Card from "../card";
56
import "./index.scss";
67

7-
// !!! FIXME: specify types
88
type Props = {
99
/** Данные по организции */
10-
data: any;
10+
data: VeryMaybe<Organization>;
1111
};
1212

1313
/**
1414
* @ItemEntity Карточка организации
1515
*/
1616
const Org = (props: Props) => {
17-
const { avatarUrl, login, description, url } = props.data as Partial<
18-
import("models").Organization
19-
>;
17+
const { avatarUrl, login, description, url } = props.data || {};
18+
2019
return (
2120
<Card
2221
className="org"

src/shared/components/repo/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import React from "react";
22
import cn from "classnames";
33
import { HeartFilled, HeartOutlined } from "@ant-design/icons";
44
import dayjs from "dayjs";
5-
import { Repository } from "models";
5+
import { VeryMaybe, Repository } from "models";
66
import Card from "../card";
77
import Lang from "./lang";
88
import "./index.scss";
99

10-
// !!! FIXME: specify types
1110
type Props = {
1211
/** Данные по репозиторию */
13-
data: any;
12+
data: VeryMaybe<Repository>;
1413
/** Формат отображения заголовка */
1514
format?: "owner-repo" | "repo";
1615
/** @handler star/unstar */
@@ -24,13 +23,7 @@ type Props = {
2423
*/
2524
const Repo = (props: Props) => {
2625
const { format = "repo", onStarring, loading } = props;
27-
const {
28-
name,
29-
primaryLanguage,
30-
updatedAt,
31-
viewerHasStarred: starred,
32-
owner,
33-
} = props.data as Partial<Repository>;
26+
const { name, primaryLanguage, updatedAt, viewerHasStarred: starred, owner } = props.data || {};
3427
// prettier-ignore
3528
const title = (
3629
(format === "owner-repo" && `${owner?.login}/${name}`) ||

src/shared/components/user/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React from "react";
22
import { Button } from "antd";
3+
import { VeryMaybe, User } from "models";
34
import Card from "../card";
45

5-
// !!! FIXME: specify types
66
type Props = {
77
/** Данные по пользователю */
8-
data: any;
8+
data: VeryMaybe<User>;
99
/** @handler follow/unfollow */
1010
onFollowing?: Callback;
1111
};
1212

1313
/**
1414
* @ItemEntity Карточка пользователя
1515
*/
16-
const User = (props: Props) => {
16+
const UserCard = (props: Props) => {
1717
const { data, onFollowing } = props;
18-
const { avatarUrl, login, viewerIsFollowing, bio } = data as Partial<import("models").User>;
18+
const { avatarUrl, login, viewerIsFollowing, bio } = data || {};
1919
return (
2020
<Card
2121
className="user"
@@ -38,4 +38,4 @@ const User = (props: Props) => {
3838
);
3939
};
4040

41-
export default User;
41+
export default UserCard;

0 commit comments

Comments
 (0)