Skip to content

Commit c693e5f

Browse files
authored
fix: new round of ts-strict fixes (#5871)
1 parent cd395ed commit c693e5f

14 files changed

Lines changed: 37 additions & 39 deletions

packages/shared/src/hooks/bookmark/useBookmarkFolder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface UseBookmarkFolder {
1818
query: {
1919
isPending: boolean;
2020
isReady: boolean;
21-
folder: BookmarkFolder;
21+
folder?: BookmarkFolder;
2222
};
2323
update: {
2424
isPending: boolean;
@@ -62,7 +62,7 @@ export const useBookmarkFolder = ({
6262

6363
logEvent({
6464
event_name: LogEvent.RenameBookmarkFolder,
65-
target_id: folder.id,
65+
target_id: folder!.id,
6666
});
6767
},
6868
onError: () => {

packages/shared/src/hooks/integrations/slack/useSlack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export const useSlack = (): UseSlack => {
3737
const redirectUrl = new URL(`${apiUrl}/integrations/slack/auth/callback`);
3838
url.searchParams.append('redirect_uri', redirectUrl.toString());
3939

40-
url.searchParams.append('state', user.id);
40+
url.searchParams.append('state', user!.id);
4141
url.searchParams.append('scope', scopes.join(','));
4242
url.searchParams.append(
4343
'client_id',
44-
process.env.NEXT_PUBLIC_SLACK_CLIENT_ID,
44+
process.env.NEXT_PUBLIC_SLACK_CLIENT_ID!,
4545
);
4646

4747
setCookie('slackRedirectPath', redirectPath, {
@@ -54,7 +54,7 @@ export const useSlack = (): UseSlack => {
5454

5555
window.location.href = url.toString();
5656
},
57-
[user?.id],
57+
[user],
5858
);
5959

6060
const connectSource = useCallback<UseSlack['connectSource']>(

packages/shared/src/hooks/post/usePostCodeSnippets.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const usePostCodeSnippetsQuery = ({
4242
const enabled = !!postId;
4343

4444
const queryResult = useInfiniteQuery({
45-
queryKey: generateQueryKey(RequestKey.PostCodeSnippets, null, {
45+
queryKey: generateQueryKey(RequestKey.PostCodeSnippets, undefined, {
4646
id: postId,
4747
}),
4848
queryFn: async ({ pageParam }) => {
@@ -65,10 +65,6 @@ export const usePostCodeSnippetsQuery = ({
6565
: enabled,
6666
getNextPageParam: (lastPage) => getNextPageParam(lastPage?.pageInfo),
6767
select: useCallback((data: InfiniteData<UsePostCodeSnippetsData>) => {
68-
if (!data) {
69-
return undefined;
70-
}
71-
7268
return {
7369
...data,
7470
// filter out last page with no edges returned by api paginator

packages/shared/src/hooks/post/usePostImage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
22
import { PostType } from '../../graphql/posts';
33
import type { Post } from '../../graphql/posts';
44

5-
export const usePostImage = (post: Post): string =>
5+
export const usePostImage = (post: Post): string | undefined =>
66
useMemo(() => {
77
if (post?.type === PostType.SocialTwitter && post?.subType === 'thread') {
88
return undefined;
@@ -15,10 +15,10 @@ export const usePostImage = (post: Post): string =>
1515
}
1616

1717
const parser = new DOMParser();
18-
const doc = parser.parseFromString(post?.contentHtml, 'text/html');
18+
const doc = parser.parseFromString(post?.contentHtml ?? '', 'text/html');
1919
const imgTag = doc.querySelector('img');
2020
if (imgTag) {
21-
return imgTag.getAttribute('src');
21+
return imgTag.getAttribute('src') ?? undefined;
2222
}
2323

2424
return undefined;

packages/shared/src/hooks/post/useRelatedPosts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type UseRelatedPostsProps = {
2929
type RelatedPostsQueryData = Connection<RelatedPost>;
3030

3131
export type UseRelatedPosts = {
32-
relatedPosts: InfiniteData<RelatedPostsQueryData>;
32+
relatedPosts?: InfiniteData<RelatedPostsQueryData>;
3333
isLoading: boolean;
3434
hasNextPage: boolean;
3535
fetchNextPage: UseInfiniteQueryResult['fetchNextPage'];
@@ -51,7 +51,7 @@ export const useRelatedPosts = ({
5151
fetchNextPage,
5252
isFetchingNextPage,
5353
} = useInfiniteQuery({
54-
queryKey: generateQueryKey(RequestKey.RelatedPosts, null, {
54+
queryKey: generateQueryKey(RequestKey.RelatedPosts, undefined, {
5555
id: postId,
5656
type: relationType,
5757
}),

packages/shared/src/hooks/post/useViewPost.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export const useViewPost = (): UseMutateAsyncFunction<
2020
onSuccess: async () => {
2121
const streak = client.getQueryData<UserStreak>(streakKey);
2222
const isNewStreak = !streak?.lastViewAt;
23-
const isFirstViewToday = !isSameDayInTimezone(
24-
new Date(streak?.lastViewAt),
25-
new Date(),
26-
user.timezone,
27-
);
23+
const isFirstViewToday =
24+
!isNewStreak &&
25+
!isSameDayInTimezone(
26+
new Date(streak!.lastViewAt!),
27+
new Date(),
28+
user!.timezone,
29+
);
2830

2931
if (isNewStreak || isFirstViewToday) {
3032
await client.refetchQueries({ queryKey: streakKey });

packages/shared/src/hooks/profile/useDevCard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface DevCardQueryData {
3131
}
3232

3333
export interface UseDevCard {
34-
devcard: DevCardData;
34+
devcard: Partial<DevCardData> & { streak: { max: number } };
3535
isLoading: boolean;
3636
coverImage: string;
3737
}
@@ -53,13 +53,13 @@ export const useDevCard = (userId: string): UseDevCard => {
5353

5454
const { isProfileCover, user } = devCard ?? {};
5555
const coverImage =
56-
(isProfileCover ? user.cover : undefined) ??
56+
(isProfileCover ? user!.cover : undefined) ??
5757
cloudinaryDevcardDefaultCoverImage;
5858

5959
return {
6060
devcard: {
6161
...devCard,
62-
streak: { ...userStreakProfile },
62+
streak: { max: userStreakProfile?.max ?? 0 },
6363
},
6464
isLoading,
6565
coverImage,

packages/shared/src/hooks/profile/useProfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export function useProfile(initialUser?: PublicProfile): {
1616
});
1717
const { data: user } = useQuery({
1818
queryKey: userQueryKey,
19-
queryFn: () => getProfile(initialUser?.id),
19+
queryFn: () => getProfile(initialUser!.id),
2020
...disabledRefetch,
2121
staleTime: StaleTime.OneHour,
2222
initialData: initialUser,
2323
enabled: !!initialUser?.id,
2424
});
2525

2626
return {
27-
user,
27+
user: user!,
2828
userQueryKey,
2929
isUserSame: !!(loggedUser && loggedUser?.id === initialUser?.id),
3030
};

packages/shared/src/hooks/source/useSourcePostModerationById.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useAuthContext } from '../../contexts/AuthContext';
55
import { getSourcePostModeration } from '../../graphql/posts';
66

77
interface UseSourcePostModerationById {
8-
moderated: SourcePostModeration;
8+
moderated?: SourcePostModeration;
99
isLoading: boolean;
1010
}
1111

@@ -21,7 +21,7 @@ export const useSourcePostModerationById = ({
2121
const { user } = useAuthContext();
2222
const { data, isLoading } = useQuery({
2323
queryKey: generateQueryKey(RequestKey.SourcePostModeration, user, id),
24-
queryFn: () => getSourcePostModeration({ id }),
24+
queryFn: () => getSourcePostModeration({ id: id! }),
2525
enabled: !!id && enabled,
2626
});
2727

packages/shared/src/hooks/streaks/useReadingStreak.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type UpdateReadingStreakConfig = {
2020
};
2121

2222
interface UserReadingStreak {
23-
streak: UserStreak;
23+
streak?: UserStreak;
2424
isLoading: boolean;
2525
isUpdatingConfig: boolean;
2626
checkReadingStreak: () => void;
@@ -67,7 +67,7 @@ export const useReadingStreak = (): UserReadingStreak => {
6767
isSameDayInTimezone(
6868
new Date(streak.lastViewAt),
6969
new Date(),
70-
user.timezone,
70+
user!.timezone,
7171
);
7272

7373
if (!hasReadToday) {

0 commit comments

Comments
 (0)