Skip to content

Commit

Permalink
chore: Safe typing for attribute editor (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlanigan committed Sep 7, 2023
1 parent 4df7f8d commit a7a9038
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = {
},
},
{
files: ['none'],
files: ['src/attribute-editor/**'],
excludedFiles: [
'src/**/__tests__/**',
'src/**/__integ__/**',
Expand Down
1 change: 1 addition & 0 deletions src/attribute-editor/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export namespace AttributeEditorProps {
focusAddButton(): void;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface I18nStrings<T = any> {
errorIconAriaLabel?: string;
itemRemovedAriaLive?: string;
Expand Down
9 changes: 8 additions & 1 deletion src/attribute-editor/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ function render<T>(
itemIndex: number,
slot: AttributeEditorProps.FieldRenderable<T> | React.ReactNode | undefined
) {
return typeof slot === 'function' ? slot(item, itemIndex) : slot;
if (isSlotFunction(slot)) {
return slot(item, itemIndex);
}
return slot;

function isSlotFunction(slot: unknown): slot is AttributeEditorProps.FieldRenderable<T> {
return typeof slot === 'function';
}
}

const GRID_DEFINITION = [{ colspan: { default: 12, xs: 9 } }];
Expand Down

0 comments on commit a7a9038

Please sign in to comment.