Skip to content

Commit 1803798

Browse files
committed
refactor type reusability
1 parent af19b72 commit 1803798

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type Frontmatter = RoadmapFrontmatter &
3535
TutorialFrontmatter
3636

3737
export type LayoutMappingType = typeof layoutMapping
38+
export type Layout = keyof LayoutMappingType
3839

3940
export type Lang =
4041
| "en"

src/pages/[...slug].tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import readingTime from "reading-time"
1414
import remarkGfm from "remark-gfm"
1515

1616
import type {
17+
Layout,
1718
LayoutMappingType,
1819
NextPageWithLayout,
1920
TocNodeType,
@@ -94,10 +95,7 @@ export const getStaticPaths = (({ locales }) => {
9495
}
9596
}) satisfies GetStaticPaths<Params>
9697

97-
type Props = Omit<
98-
Parameters<LayoutMappingType[keyof LayoutMappingType]>[0],
99-
"children"
100-
> &
98+
type Props = Omit<Parameters<LayoutMappingType[Layout]>[0], "children"> &
10199
SSRConfig & {
102100
mdxSource: MDXRemoteSerializeResult
103101
}
@@ -138,7 +136,7 @@ export const getStaticProps = (async (context) => {
138136
const lastDeployDate = getLastDeployDate()
139137

140138
// Get corresponding layout
141-
let layout = (frontmatter.template as keyof LayoutMappingType) ?? "static"
139+
let layout = (frontmatter.template as Layout) ?? "static"
142140

143141
if (!frontmatter.template) {
144142
if (params.slug.includes("docs")) {

0 commit comments

Comments
 (0)