From 8166b0ba163cd8cb2902c99abf6c3e953f0a430b Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni Date: Sat, 19 Oct 2024 00:05:03 +0530 Subject: [PATCH 1/6] website#1034 added Typescript strictness --- components/Code.tsx | 4 +- components/DocTable.tsx | 19 ++- components/GettingStarted.tsx | 69 +++++++---- components/Headlines.tsx | 19 ++- components/Layout.tsx | 31 +++-- components/NextPrevButton.tsx | 35 ++---- next-env.d.ts | 2 +- pages/[slug].page.tsx | 34 +++++- pages/blog/posts/[slug].page.tsx | 82 ++++++++----- pages/draft-05/index.page.tsx | 20 +++- pages/draft-06/[slug].page.tsx | 36 +++++- pages/draft-06/index.page.tsx | 18 ++- pages/draft-07/[slug].page.tsx | 36 +++++- pages/draft-07/index.page.tsx | 18 ++- pages/draft/2019-09/[slug].page.tsx | 36 +++++- pages/draft/2019-09/index.page.tsx | 18 ++- pages/draft/2020-12/[slug].page.tsx | 36 +++++- pages/draft/2020-12/index.page.tsx | 18 ++- pages/implementers/[slug].page.tsx | 36 +++++- pages/implementers/index.page.tsx | 2 +- pages/learn/[slug].page.tsx | 25 +++- .../index.page.tsx | 13 +- pages/obsolete-implementations/index.page.tsx | 99 ++++++++------- pages/overview/[slug].page.tsx | 37 +++++- pages/overview/code-of-conduct/index.page.tsx | 2 +- pages/overview/sponsors/index.page.tsx | 2 +- .../json-hyper-schema/index.page.tsx | 20 ++-- pages/specification/migration/index.page.tsx | 20 ++-- .../release-notes/index.page.tsx | 113 +++++++++++------- pages/tools/components/ToolingTable.tsx | 41 ++++--- .../understanding-json-schema/[slug].page.tsx | 34 +++++- .../understanding-json-schema/index.page.tsx | 2 +- .../reference/[slug].page.tsx | 34 +++++- .../reference/index.page.tsx | 3 +- 34 files changed, 716 insertions(+), 298 deletions(-) diff --git a/components/Code.tsx b/components/Code.tsx index 7460fa4e8..5d87597ee 100644 --- a/components/Code.tsx +++ b/components/Code.tsx @@ -1,8 +1,8 @@ -import React, { useContext } from 'react'; +import React, { useContext, ReactNode } from 'react'; import classnames from 'classnames'; import { BlockContext, BlockContextValue } from '~/context'; -export default function Code({ children }: { children: any }) { +export default function Code({ children }: { children: ReactNode }) { // eslint-disable-next-line react-hooks/rules-of-hooks const blockContext = useContext(BlockContext); return ( diff --git a/components/DocTable.tsx b/components/DocTable.tsx index 770a660ca..d876a0a21 100644 --- a/components/DocTable.tsx +++ b/components/DocTable.tsx @@ -1,7 +1,14 @@ import React from 'react'; import Link from 'next/link'; -const DocTable = ({ frontmatter }: any) => { +type Frontmatter = { + Specification: string; + Published: string; + authors: string[]; + Metaschema: string; +}; + +const DocTable = ({ frontmatter }: { frontmatter: Frontmatter }) => { return ( <>
@@ -30,21 +37,21 @@ const DocTable = ({ frontmatter }: any) => { {frontmatter.Published} - + Authors - {frontmatter.authors.map((author: string, index: number) => { - return
{author}
; - })} + {frontmatter.authors.map((author, index) => ( +
{author}
+ ))} Metaschema - + data.default === true); + const defaultSchemaData = data.find((schema) => schema.default === true); + + if (!defaultSchemaData) { + throw new Error('Default schema not found'); + } const schemaResp = await fetch(defaultSchemaData.file); const schemaData = await schemaResp.json(); const defaultInstanceData = defaultSchemaData.instances.find( - (instance: any) => instance.default === true, + (instance) => instance.default === true, ); + if (!defaultInstanceData) { + throw new Error('Default instance not found'); + } + const instanceResp = await fetch(defaultInstanceData.file); const instanceData = await instanceResp.json(); @@ -29,17 +64,6 @@ async function fetchData() { }; } -interface SchemaOption { - file: string; - instances: InstanceOption[]; -} - -interface InstanceOption { - file: string; - details: string; - valid: string; -} - const GettingStarted = () => { useEffect(() => { fetchData() @@ -64,8 +88,10 @@ const GettingStarted = () => { const [options, setOptions] = useState([]); const [instances, setInstances] = useState([]); const [details, setDetails] = useState(['', '']); - const [fetchedSchema, setFetchedSchema] = useState(); - const [fetchedInstance, setFetchedInstance] = useState(); + const [fetchedSchema, setFetchedSchema] = useState(null); + const [fetchedInstance, setFetchedInstance] = useState( + null, + ); const handleSchemaChange = async ( e: React.ChangeEvent, @@ -86,7 +112,7 @@ const GettingStarted = () => { setFetchedInstance(instData); } else { setInstances([]); - setFetchedSchema(null!); + setFetchedSchema(null); } }; @@ -104,7 +130,7 @@ const GettingStarted = () => { setFetchedInstance(instanceData); setDetails([selectedInstance.details, selectedInstance.valid]); } else { - setFetchedInstance(undefined); + setFetchedInstance(null); } }; @@ -125,6 +151,7 @@ const GettingStarted = () => { return ( <>
+ {/* Schema Select and Display */}

JSON Schema

@@ -138,7 +165,7 @@ const GettingStarted = () => { id='Examples' onChange={handleSchemaChange} > - {options.map((option: any, id: number) => ( + {options.map((option, id) => ( @@ -180,6 +207,7 @@ const GettingStarted = () => {
+ {/* Instance Select and Display */}

JSON Instance

@@ -193,7 +221,7 @@ const GettingStarted = () => { id='Examples' onChange={handleInstanceChange} > - {instances.map((instance: any, id: number) => ( + {instances.map((instance, id) => ( @@ -244,6 +272,7 @@ const GettingStarted = () => {
+ {/* Download Button */}