Skip to content

Commit 516b871

Browse files
committed
fix typings
1 parent e72ac64 commit 516b871

File tree

13 files changed

+81
-78
lines changed

13 files changed

+81
-78
lines changed

src/components/BlogSidebar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
}
88

99
const BlogSidebar = ({ posts, currentPermalink }: Props) => {
10-
const allTags = useStaticQuery(graphql`
10+
const allTags = useStaticQuery<GatsbyTypes.allTagsQuery>(graphql`
1111
query allTags {
1212
allMarkdownRemark {
1313
group(field: frontmatter___tags) {
@@ -28,7 +28,7 @@ const BlogSidebar = ({ posts, currentPermalink }: Props) => {
2828
<div className="nav-docs-section categories">
2929
<h3>Categories</h3>
3030
<ul>
31-
{allTags.map(({ fieldValue }: { fieldValue: string }, i: number) => {
31+
{allTags.map(({ fieldValue = '' }, i: number) => {
3232
const tag = fieldValue[0].toUpperCase() + fieldValue.substring(1)
3333
return (
3434
<li key={i}>

src/components/Footer/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface FooterLinks {
1313
subsections: LinkItem[]
1414
}
1515

16-
const getLinks = (sourcePath: string): FooterLinks[] => [
16+
const getLinks = (sourcePath?: string): FooterLinks[] => [
1717
{
1818
text: "Learn",
1919
href: "/learn/",
@@ -70,18 +70,18 @@ const getLinks = (sourcePath: string): FooterLinks[] => [
7070
{ text: "Logo and Brand Guidelines", href: "/brand" },
7171
{ text: "Code of Conduct", href: "/codeofconduct/" },
7272
{ text: "Contact Us", href: "/foundation/contact/" },
73-
{
73+
sourcePath && {
7474
text: "Edit this page",
7575
href:
7676
"https://github.com/graphql/graphql.github.io/edit/source/" +
7777
sourcePath,
7878
icon: "/img/edit.svg",
7979
},
80-
],
80+
].filter(Boolean) as LinkItem[],
8181
},
8282
]
8383

84-
const Footer = ({ sourcePath }: { sourcePath: string }) => {
84+
const Footer = ({ sourcePath }: { sourcePath?: string }) => {
8585
return (
8686
<div>
8787
<footer>

src/components/Layout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Seo from "../Seo"
66
import "../../assets/css/style.less"
77

88
interface PageContext {
9-
sourcePath: string
9+
sourcePath?: string
1010
}
1111

1212
interface Props {

src/components/Seo/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface Props {
88
}
99

1010
const Seo = ({ title, description }: Props): JSX.Element => {
11-
const data = useStaticQuery(graphql`
11+
const data = useStaticQuery<GatsbyTypes.SeoQueryQuery>(graphql`
1212
query SeoQuery {
1313
site {
1414
siteMetadata {

src/pages/blog.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import Layout from "../components/Layout"
33
import BlogPost from "../components/BlogPost"
44
import BlogSidebar from "../components/BlogSidebar"
55
import { graphql } from "gatsby"
6+
import type { PageProps } from "gatsby";
67

7-
export default ({ pageContext, data }: any) => {
8+
export default ({ pageContext, data }: PageProps<GatsbyTypes.GetAllBlogPostsQuery, GatsbyTypes.SitePageContext>) => {
89
const posts = data.allMarkdownRemark.edges
9-
.map((e: any) => e.node)
10-
.sort((a: any, b: any) => {
11-
const aDate = new Date(a.frontmatter.date)
12-
const bDate = new Date(b.frontmatter.date)
10+
.map(e => e.node)
11+
.sort((a, b) => {
12+
const aDate = new Date(a?.frontmatter?.date ?? 0)
13+
const bDate = new Date(b?.frontmatter?.date ?? 0)
1314
if (aDate > bDate) {
1415
return -1
1516
} else if (aDate < bDate) {
@@ -64,7 +65,7 @@ export default ({ pageContext, data }: any) => {
6465
}
6566

6667
export const query = graphql`
67-
query getAllBlogPosts {
68+
query GetAllBlogPosts {
6869
allMarkdownRemark(
6970
filter: { frontmatter: { permalink: { regex: "/blog/" } } }
7071
) {

src/pages/brand.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useState } from "react"
2+
import type { PageProps } from "gatsby"
23
import Layout from "../components/Layout"
34

4-
export default ({ pageContext }) => {
5+
export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>) => {
56
return (
67
<Layout
78
title="GraphQL logo, brand guidelines and assets"

src/pages/code.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
import type { PageProps } from "gatsby"
12
import { AnchorLink } from "gatsby-plugin-anchor-links"
23
import React, { useState } from "react"
34
import Layout from "../components/Layout"
45
import Marked from "../components/Marked"
56
import { toSlug } from "../utils/slug"
67

7-
export function buildLanguagesMenu(pageContext: any) {
8+
export function buildLanguagesMenu(pageContext: GatsbyTypes.SitePageContext) {
89
return (
910
<div className="language-boxes">
10-
{pageContext.languageList.map(({ name: languageName }) => {
11-
const slug = toSlug(languageName)
12-
return (
13-
<AnchorLink
14-
to={`#${slug}`}
15-
className="article language-box"
16-
title={languageName}
17-
>
18-
<span className="article_title">{languageName}</span>
19-
</AnchorLink>
20-
)
21-
})}
11+
{pageContext.languageList
12+
?.map(langeuage => langeuage?.name!).filter(Boolean)
13+
.map(languageName => {
14+
const slug = toSlug(languageName)
15+
return (
16+
<AnchorLink
17+
to={`#${slug}`}
18+
className="article language-box"
19+
title={languageName}
20+
>
21+
<span className="article_title">{languageName}</span>
22+
</AnchorLink>
23+
)
24+
})
25+
}
2226
</div>
2327
)
2428
}
2529

26-
export function buildLibraryContent(library: any, pageContext: any) {
30+
export function buildLibraryContent(library: any, pageContext: GatsbyTypes.SitePageContext) {
2731
const [ overflown, setOverflown ] = useState(false);
2832
const [ expanded, setExpanded ] = useState(false);
2933
return (
@@ -113,7 +117,7 @@ export function buildLibraryContent(library: any, pageContext: any) {
113117
)
114118
}
115119

116-
export function buildLibraryList(libraries: any[], pageContext: any) {
120+
export function buildLibraryList(libraries: readonly any[], pageContext: any) {
117121
return (
118122
<div className="library-list">
119123
{libraries.map(library => buildLibraryContent(library, pageContext))}
@@ -194,7 +198,7 @@ export function buildLanguagesContent(pageContext: any) {
194198
return <div className="languages-content">{elements}</div>
195199
}
196200

197-
export default ({ pageContext }: any) => {
201+
export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>) => {
198202
return (
199203
<Layout title="GraphQL Code Libraries, Tools and Services" className="code" pageContext={pageContext}>
200204
<div className="code-hero">
@@ -240,15 +244,15 @@ export default ({ pageContext }: any) => {
240244
#
241245
</AnchorLink>
242246
</h2>
243-
{buildLibraryList(pageContext.otherLibraries.Tools, pageContext)}
247+
{buildLibraryList(pageContext.otherLibraries?.Tools ?? [], pageContext)}
244248
<h2>
245249
<a className="anchor" id="services"></a>
246250
Services
247251
<AnchorLink className="hash-link" to="#services">
248252
#
249253
</AnchorLink>
250254
</h2>
251-
{buildLibraryList(pageContext.otherLibraries.Services, pageContext)}
255+
{buildLibraryList(pageContext.otherLibraries?.Services ?? [], pageContext)}
252256
</div>
253257
</div>
254258
<p>Want to improve this page? See the <a href="https://github.com/graphql/graphql.github.io/blob/source/notes/ContributingToCodePage.md">docs here</a>.</p>

src/pages/faq.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React from "react"
22
import Layout from "../components/Layout"
33
import FAQSection from "../components/FAQSection"
4+
import type { PageProps } from "gatsby"
45
import { graphql } from "gatsby"
56
import { useFAQAccordion } from "../utils/useFAQAccordion"
67

7-
export default ({ pageContext, data }: any) => {
8+
export default ({ pageContext, data }: PageProps<GatsbyTypes.GetAllFAQSectionsQuery, GatsbyTypes.SitePageContext>) => {
89
useFAQAccordion()
910

1011
const sections = data.allMarkdownRemark.edges
11-
.map((e: any) => e.node)
12-
.sort((a: any, b: any) => {
13-
const aPosition = a.frontmatter.position
14-
const bPosition = b.frontmatter.position
12+
.map(e => e.node)
13+
.sort((a, b) => {
14+
const aPosition = a?.frontmatter?.position ?? 0
15+
const bPosition = b?.frontmatter?.position ?? 0
1516
if (aPosition < bPosition) {
1617
return -1
1718
}
@@ -28,16 +29,15 @@ export default ({ pageContext, data }: any) => {
2829
{sections.map(
2930
(
3031
{
31-
frontmatter: { title, permalink },
32+
frontmatter: { title } = {},
3233
rawMarkdownBody,
33-
}: any,
34+
},
3435
i
3536
) => (
3637
<FAQSection
3738
key={i}
38-
title={title}
39-
permalink={permalink}
40-
rawMarkdownBody={rawMarkdownBody}
39+
title={title!}
40+
rawMarkdownBody={rawMarkdownBody!}
4141
pageContext={pageContext}
4242
/>
4343
)
@@ -51,7 +51,7 @@ export default ({ pageContext, data }: any) => {
5151
}
5252

5353
export const query = graphql`
54-
query getAllFAQSections {
54+
query GetAllFAQSections {
5555
allMarkdownRemark(
5656
filter: { frontmatter: { permalink: { regex: "/faq/" } } }
5757
) {

src/pages/foundation/members.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react"
2+
import type { PageProps } from "gatsby"
23
import Layout from "../../components/Layout"
34

4-
export default ({ pageContext }) => {
5+
export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>) => {
56
return (
67
<Layout title="GraphQL Foundation Members | GraphQL" pageContext={pageContext}>
78
<section className="foundation-members-page">

src/pages/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react"
2+
import type { PageProps } from "gatsby"
23
import Layout from "../components/Layout"
34

45
import Hero from "../Containers/Sections/Hero"
@@ -10,7 +11,7 @@ import WithoutVersions from "../Containers/Sections/WithoutVersion"
1011
import PowerFulTools from "../Containers/Sections/PowerFulTools"
1112
import WhosUsing from "../Containers/Sections/WhosUsing"
1213

13-
export default ({ pageContext }) => {
14+
export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>) => {
1415
return (
1516
<Layout className={"index"} title="GraphQL | A query language for your API" pageContext={pageContext}>
1617
<Hero />

0 commit comments

Comments
 (0)