Skip to content

Commit fd42ad5

Browse files
authored
chore(plugin-nested-docs): enable TypeScript strict (#11930)
1 parent a58ff57 commit fd42ad5

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

packages/plugin-nested-docs/src/fields/parentFilterOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export const parentFilterOptions: (breadcrumbsFieldSlug?: string) => FilterOptio
1010
}
1111
}
1212

13-
return null
13+
return true
1414
}

packages/plugin-nested-docs/src/hooks/resaveChildren.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ const resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs)
5858
},
5959
})
6060

61-
const childrenById = [...draftChildren, ...publishedChildren.docs].reduce((acc, child) => {
61+
const childrenById = [...draftChildren, ...publishedChildren.docs].reduce<
62+
Record<string, JsonObject[]>
63+
>((acc, child) => {
6264
acc[child.id] = acc[child.id] || []
63-
acc[child.id].push(child)
65+
acc[child.id]!.push(child)
6466
return acc
6567
}, {})
6668

packages/plugin-nested-docs/src/hooks/resaveSelfAfterCreate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'
22

3-
import type { NestedDocsPluginConfig } from '../types.js'
3+
import type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'
44

55
// This hook automatically re-saves a document after it is created
66
// so that we can build its breadcrumbs with the newly created document's ID.
@@ -10,7 +10,7 @@ export const resaveSelfAfterCreate =
1010
async ({ doc, operation, req }) => {
1111
const { locale, payload } = req
1212
const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'
13-
const breadcrumbs = doc[breadcrumbSlug]
13+
const breadcrumbs = doc[breadcrumbSlug] as unknown as Breadcrumb[]
1414

1515
if (operation === 'create') {
1616
const originalDocWithDepth0 = await payload.findByID({

packages/plugin-nested-docs/src/utilities/formatBreadcrumb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const formatBreadcrumb = (
1010
let url: string | undefined = undefined
1111
let label: string
1212

13-
const lastDoc = docs[docs.length - 1]
13+
const lastDoc = docs[docs.length - 1]!
1414

1515
if (typeof pluginConfig?.generateURL === 'function') {
1616
url = pluginConfig.generateURL(docs, lastDoc)
@@ -19,7 +19,7 @@ export const formatBreadcrumb = (
1919
if (typeof pluginConfig?.generateLabel === 'function') {
2020
label = pluginConfig.generateLabel(docs, lastDoc)
2121
} else {
22-
const title = lastDoc[collection.admin.useAsTitle]
22+
const title = collection.admin?.useAsTitle ? lastDoc[collection.admin.useAsTitle] : ''
2323

2424
label = typeof title === 'string' || typeof title === 'number' ? String(title) : ''
2525
}

packages/plugin-nested-docs/src/utilities/getParents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const getParents = async (
1111
): Promise<Array<Record<string, unknown>>> => {
1212
const parentSlug = pluginConfig?.parentFieldSlug || 'parent'
1313
const parent = doc[parentSlug]
14-
let retrievedParent
14+
let retrievedParent: null | Record<string, unknown> = null
1515

1616
if (parent) {
1717
// If not auto-populated, and we have an ID
@@ -27,7 +27,7 @@ export const getParents = async (
2727

2828
// If auto-populated
2929
if (typeof parent === 'object') {
30-
retrievedParent = parent
30+
retrievedParent = parent as Record<string, unknown>
3131
}
3232

3333
if (retrievedParent) {
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
22
"extends": "../../tsconfig.base.json",
3-
"compilerOptions": {
4-
/* TODO: remove the following lines */
5-
"strict": false,
6-
},
73
"references": [{ "path": "../payload" }]
84
}

0 commit comments

Comments
 (0)