Replaced Exclude with NonNullable

This commit is contained in:
DrMint 2022-05-15 01:15:57 +02:00
parent 2e62f25fb5
commit ed7198807f
19 changed files with 81 additions and 144 deletions

View File

@ -7,15 +7,12 @@ import { Immutable } from "helpers/types";
import { useState } from "react"; import { useState } from "react";
interface Props { interface Props {
content: Exclude< content: NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
GetLibraryItemQuery["libraryItems"], GetLibraryItemQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"], >["contents"]
null | undefined
>["contents"],
null | undefined
>["data"][number]; >["data"][number];
parentSlug: string; parentSlug: string;
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];
@ -43,7 +40,8 @@ export function ContentLine(props: Immutable<Props>): JSX.Element {
? prettyinlineTitle( ? prettyinlineTitle(
content.attributes.content.data.attributes.translations[0] content.attributes.content.data.attributes.translations[0]
?.pre_title, ?.pre_title,
content.attributes.content.data.attributes.translations[0]?.title, content.attributes.content.data.attributes.translations[0]
?.title,
content.attributes.content.data.attributes.translations[0] content.attributes.content.data.attributes.translations[0]
?.subtitle ?.subtitle
) )

View File

@ -13,38 +13,29 @@ import { useSmartLanguage } from "hooks/useSmartLanguage";
interface Props { interface Props {
openLightBox: (images: string[], index?: number) => void; openLightBox: (images: string[], index?: number) => void;
scanSet: Exclude< scanSet: NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"], >["contents"]
null | undefined >["data"][number]["attributes"]
>["contents"], >["scan_set"]
null | undefined
>["data"][number]["attributes"],
null | undefined
>["scan_set"],
null | undefined
>; >;
slug: string; slug: string;
title: string; title: string;
languages: AppStaticProps["languages"]; languages: AppStaticProps["languages"];
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];
content: Exclude< content: NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"], >["contents"]
null | undefined >["data"][number]["attributes"]
>["contents"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>["content"]; >["content"];
} }
@ -57,7 +48,7 @@ export function ScanSet(props: Immutable<Props>): JSX.Element {
languages: languages, languages: languages,
languageExtractor: (item) => item.language?.data?.attributes?.code, languageExtractor: (item) => item.language?.data?.attributes?.code,
transform: (item) => { transform: (item) => {
const newItem = { ...item } as Exclude<Props["scanSet"][number], null>; const newItem = { ...item } as NonNullable<Props["scanSet"][number]>;
newItem.pages?.data.sort((a, b) => { newItem.pages?.data.sort((a, b) => {
if (a.attributes?.url && b.attributes?.url) { if (a.attributes?.url && b.attributes?.url) {
let aName = getAssetFilename(a.attributes.url); let aName = getAssetFilename(a.attributes.url);

View File

@ -14,15 +14,12 @@ import { useSmartLanguage } from "hooks/useSmartLanguage";
interface Props { interface Props {
openLightBox: (images: string[], index?: number) => void; openLightBox: (images: string[], index?: number) => void;
images: Exclude< images: NonNullable<
Exclude< NonNullable<
Exclude< NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"], >["images"]
null | undefined
>["images"],
null | undefined
>; >;
languages: AppStaticProps["languages"]; languages: AppStaticProps["languages"];
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];

View File

@ -14,19 +14,11 @@ interface Props {
title: string | null | undefined; title: string | null | undefined;
subtitle?: string | null | undefined; subtitle?: string | null | undefined;
description?: string | null | undefined; description?: string | null | undefined;
type?: Exclude< type?: NonNullable<
Exclude< NonNullable<GetContentTextQuery["contents"]>["data"][number]["attributes"]
GetContentTextQuery["contents"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>["type"]; >["type"];
categories?: Exclude< categories?: NonNullable<
Exclude< NonNullable<GetContentTextQuery["contents"]>["data"][number]["attributes"]
GetContentTextQuery["contents"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>["categories"]; >["categories"];
thumbnail?: UploadImageFragment | null | undefined; thumbnail?: UploadImageFragment | null | undefined;
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];

View File

@ -9,10 +9,7 @@ import { getStatusDescription } from "helpers/others";
import { Immutable } from "helpers/types"; import { Immutable } from "helpers/types";
interface Props { interface Props {
item: Exclude< item: NonNullable<GetChronologyItemsQuery["chronologyItems"]>["data"][number];
GetChronologyItemsQuery["chronologyItems"],
null | undefined
>["data"][number];
displayYear: boolean; displayYear: boolean;
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];
} }

View File

@ -5,9 +5,8 @@ import { Immutable } from "helpers/types";
interface Props { interface Props {
year: number; year: number;
items: Exclude< items: NonNullable<
GetChronologyItemsQuery["chronologyItems"], GetChronologyItemsQuery["chronologyItems"]
null | undefined
>["data"][number][]; >["data"][number][];
langui: AppStaticProps["langui"]; langui: AppStaticProps["langui"];
} }

View File

@ -8,18 +8,13 @@ import { Immutable } from "helpers/types";
import { GetStaticPropsContext } from "next"; import { GetStaticPropsContext } from "next";
export type AppStaticProps = Immutable<{ export type AppStaticProps = Immutable<{
langui: Exclude< langui: NonNullable<
Exclude< NonNullable<
GetWebsiteInterfaceQuery["websiteInterfaces"], GetWebsiteInterfaceQuery["websiteInterfaces"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"],
null | undefined
>; >;
currencies: Exclude< currencies: NonNullable<GetCurrenciesQuery["currencies"]>["data"];
GetCurrenciesQuery["currencies"], languages: NonNullable<GetLanguagesQuery["languages"]>["data"];
null | undefined
>["data"];
languages: Exclude<GetLanguagesQuery["languages"], null | undefined>["data"];
}>; }>;
export async function getAppStaticProps( export async function getAppStaticProps(

View File

@ -4,7 +4,7 @@ import { Immutable } from "./types";
export function convertPrice( export function convertPrice(
pricePicker: Immutable<PricePickerFragment>, pricePicker: Immutable<PricePickerFragment>,
targetCurrency: Immutable< targetCurrency: Immutable<
Exclude<GetCurrenciesQuery["currencies"], null | undefined>["data"][number] NonNullable<GetCurrenciesQuery["currencies"]>["data"][number]
> >
): number { ): number {
if ( if (

View File

@ -7,19 +7,15 @@ import { AppStaticProps } from "../graphql/getAppStaticProps";
import { Immutable } from "./types"; import { Immutable } from "./types";
type SortContentProps = type SortContentProps =
| Exclude< | NonNullable<
Exclude< NonNullable<
GetLibraryItemQuery["libraryItems"], GetLibraryItemQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"],
null | undefined
>["contents"] >["contents"]
| Exclude< | NonNullable<
Exclude< NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined >["data"][number]["attributes"]
>["data"][number]["attributes"],
null | undefined
>["contents"]; >["contents"];
export function sortContent(contents: Immutable<SortContentProps>) { export function sortContent(contents: Immutable<SortContentProps>) {

View File

@ -1,28 +1,20 @@
import { GetContentTextQuery, GetPostQuery } from "graphql/generated"; import { GetContentTextQuery, GetPostQuery } from "graphql/generated";
import React from "react"; import React from "react";
type Post = Exclude< type Post = NonNullable<
Exclude< NonNullable<GetPostQuery["posts"]>["data"][number]["attributes"]
GetPostQuery["posts"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>; >;
export interface PostWithTranslations extends Omit<Post, "translations"> { export interface PostWithTranslations extends Omit<Post, "translations"> {
translations: Exclude<Post["translations"], null | undefined>; translations: NonNullable<Post["translations"]>;
} }
type Content = Exclude< type Content = NonNullable<
Exclude< NonNullable<GetContentTextQuery["contents"]>["data"][number]["attributes"]
GetContentTextQuery["contents"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>; >;
export interface ContentWithTranslations extends Omit<Content, "translations"> { export interface ContentWithTranslations extends Omit<Content, "translations"> {
translations: Exclude<Content["translations"], null | undefined>; translations: NonNullable<Content["translations"]>;
} }
type ImmutableBlackList<T> = JSX.Element | React.ReactNode | Function; type ImmutableBlackList<T> = JSX.Element | React.ReactNode | Function;

View File

@ -8,12 +8,8 @@ import { useEffect, useMemo, useState } from "react";
interface Props<T> { interface Props<T> {
items: Immutable<T[]>; items: Immutable<T[]>;
languages: AppStaticProps["languages"]; languages: AppStaticProps["languages"];
languageExtractor: ( languageExtractor: (item: NonNullable<Immutable<T>>) => string | undefined;
item: Exclude<Immutable<T>, null | undefined> transform?: (item: NonNullable<Immutable<T>>) => NonNullable<Immutable<T>>;
) => string | undefined;
transform?: (
item: Exclude<Immutable<T>, null | undefined>
) => Exclude<Immutable<T>, null | undefined>;
} }
function getPreferredLanguage( function getPreferredLanguage(

View File

@ -23,9 +23,8 @@ import {
import { useState } from "react"; import { useState } from "react";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
channel: Exclude< channel: NonNullable<
GetVideoChannelQuery["videoChannels"], GetVideoChannelQuery["videoChannels"]
null | undefined
>["data"][number]["attributes"]; >["data"][number]["attributes"];
} }

View File

@ -21,7 +21,7 @@ import { GetStaticPropsContext } from "next";
import { useState } from "react"; import { useState } from "react";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
videos: Exclude<GetVideosPreviewQuery["videos"], null | undefined>["data"]; videos: NonNullable<GetVideosPreviewQuery["videos"]>["data"];
} }
export default function Videos(props: Props): JSX.Element { export default function Videos(props: Props): JSX.Element {

View File

@ -26,12 +26,8 @@ import {
} from "next"; } from "next";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
video: Exclude< video: NonNullable<
Exclude< NonNullable<GetVideoQuery["videos"]>["data"][number]["attributes"]
GetVideoQuery["videos"],
null | undefined
>["data"][number]["attributes"],
null | undefined
>; >;
} }

View File

@ -45,13 +45,11 @@ import {
import { useState } from "react"; import { useState } from "react";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
item: Exclude< item: NonNullable<
GetLibraryItemQuery["libraryItems"], GetLibraryItemQuery["libraryItems"]
null | undefined
>["data"][number]["attributes"]; >["data"][number]["attributes"];
itemId: Exclude< itemId: NonNullable<
GetLibraryItemQuery["libraryItems"], GetLibraryItemQuery["libraryItems"]
null | undefined
>["data"][number]["id"]; >["data"][number]["id"];
} }

View File

@ -26,13 +26,11 @@ import {
} from "next"; } from "next";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
item: Exclude< item: NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined
>["data"][number]["attributes"]; >["data"][number]["attributes"];
itemId: Exclude< itemId: NonNullable<
GetLibraryItemScansQuery["libraryItems"], GetLibraryItemScansQuery["libraryItems"]
null | undefined
>["data"][number]["id"]; >["data"][number]["id"];
} }

View File

@ -23,10 +23,7 @@ import { GetStaticPropsContext } from "next";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
items: Exclude< items: NonNullable<GetLibraryItemsPreviewQuery["libraryItems"]>["data"];
GetLibraryItemsPreviewQuery["libraryItems"],
null | undefined
>["data"];
} }
type GroupLibraryItems = Map<string, Immutable<Props["items"]>>; type GroupLibraryItems = Map<string, Immutable<Props["items"]>>;

View File

@ -16,7 +16,7 @@ import { GetStaticPropsContext } from "next";
import { useState } from "react"; import { useState } from "react";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
posts: Exclude<GetPostsPreviewQuery["posts"], null | undefined>["data"]; posts: NonNullable<GetPostsPreviewQuery["posts"]>["data"];
} }
export default function News(props: Immutable<Props>): JSX.Element { export default function News(props: Immutable<Props>): JSX.Element {

View File

@ -16,14 +16,10 @@ import { prettySlug } from "helpers/formatters";
import { GetStaticPropsContext } from "next"; import { GetStaticPropsContext } from "next";
interface Props extends AppStaticProps { interface Props extends AppStaticProps {
chronologyItems: Exclude< chronologyItems: NonNullable<
GetChronologyItemsQuery["chronologyItems"], GetChronologyItemsQuery["chronologyItems"]
null | undefined
>["data"];
chronologyEras: Exclude<
GetErasQuery["chronologyEras"],
null | undefined
>["data"]; >["data"];
chronologyEras: NonNullable<GetErasQuery["chronologyEras"]>["data"];
} }
export default function Chronology(props: Props): JSX.Element { export default function Chronology(props: Props): JSX.Element {