Skip to content

Commit

Permalink
fix: type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Dec 9, 2024
1 parent 8ce5e1f commit bdd76bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/sectionList/modelValue/ModelValueRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const ModelValueRenderer = ({
value,
schemaProperty,
}: ValueDetails) => {
const hasToStringMethod = (
value: unknown
): value is { toString: () => string } =>
typeof value === 'object' &&
typeof (value as any).toString === 'function'

if (path === 'sharing.public' && typeof value === 'string') {
return <PublicAccessValue value={value} />
}
Expand All @@ -41,8 +47,9 @@ export const ModelValueRenderer = ({
return <BooleanValue value={value} />
}

if (value ?? false) {
if (value !== null && value !== undefined && hasToStringMethod(value)) {
return <TextValue value={value.toString()} />
}

return null
}
2 changes: 2 additions & 0 deletions src/types/schemaBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface SchemaFieldProperty {
unique: boolean
required: boolean
length?: number
max?: number
min?: number
persisted: boolean
collectionName?: string
collection: boolean
Expand Down

0 comments on commit bdd76bf

Please sign in to comment.