The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(ui): no unchecked indexed access twenty UI (#26493)
BOHEUS24744ee72b22
diff --git a/packages/twenty-front/src/modules/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder.tsx b/packages/twenty-front/src/modules/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder.tsxindex eb6b6d972fe..ccfa84adcc9 100644--- a/packages/twenty-front/src/modules/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder.tsx+++ b/packages/twenty-front/src/modules/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder.tsx@@ -7,6 +7,7 @@ import { BACKGROUND } from '@/ui/feedback/empty-state/components/AnimatedPlacehoimport { DARK_BACKGROUND } from '@/ui/feedback/empty-state/components/AnimatedPlaceholder/constants/DarkBackground';import { DARK_MOVING_IMAGE } from '@/ui/feedback/empty-state/components/AnimatedPlaceholder/constants/DarkMovingImage';import { MOVING_IMAGE } from '@/ui/feedback/empty-state/components/AnimatedPlaceholder/constants/MovingImage';+import { isDefined } from 'twenty-shared/utils';import { useThemeColorScheme } from 'twenty-ui/theme';const styles = {@@ -82,17 +83,18 @@ export const AnimatedPlaceholder = ({};const handleMove = (event: MouseEvent | TouchEvent) => {- const clientX =- 'touches' in event ? event.touches[0].clientX : event.clientX;- const clientY =- 'touches' in event ? event.touches[0].clientY : event.clientY;+ const point = 'touches' in event ? event.touches[0] : event;++ if (!isDefined(point)) {+ return;+ }setParallax({offsetX:- (clientX / window.innerWidth) * 2 * PARALLAX_OFFSET_IN_PX -+ (point.clientX / window.innerWidth) * 2 * PARALLAX_OFFSET_IN_PX -PARALLAX_OFFSET_IN_PX,offsetY:- (clientY / window.innerHeight) * 2 * PARALLAX_OFFSET_IN_PX -+ (point.clientY / window.innerHeight) * 2 * PARALLAX_OFFSET_IN_PX -PARALLAX_OFFSET_IN_PX,});};diff --git a/packages/twenty-ui/design-tokens/pipeline/__tests__/collectLeaves.test.ts b/packages/twenty-ui/design-tokens/pipeline/__tests__/collectLeaves.test.tsindex c5f228df2be..1df19883b45 100644--- a/packages/twenty-ui/design-tokens/pipeline/__tests__/collectLeaves.test.ts+++ b/packages/twenty-ui/design-tokens/pipeline/__tests__/collectLeaves.test.ts@@ -24,7 +24,7 @@ describe('collectLeaves', () => {dark: '2147483647',unit: 'number',},- })[0].unit,+ })[0]?.unit,).toBe('number');});diff --git a/packages/twenty-ui/design-tokens/pipeline/buildLeafTree.ts b/packages/twenty-ui/design-tokens/pipeline/buildLeafTree.tsindex 55c8084cea5..44915355a5e 100644--- a/packages/twenty-ui/design-tokens/pipeline/buildLeafTree.ts+++ b/packages/twenty-ui/design-tokens/pipeline/buildLeafTree.ts@@ -23,6 +23,9 @@ export const buildLeafTree = ({node = child;}const leafKey = leaf.path[leaf.path.length - 1];+ if (leafKey === undefined) {+ throw new Error('Token leaf has an empty path.');+ }if (node[leafKey] !== undefined) {throw new Error(`Token path collision at "${leaf.path.join('.')}": "${leafKey}" is already defined.`,diff --git a/packages/twenty-ui/design-tokens/pipeline/buildMainColorNames.ts b/packages/twenty-ui/design-tokens/pipeline/buildMainColorNames.tsindex 607a3b424d2..28574cb3556 100644--- a/packages/twenty-ui/design-tokens/pipeline/buildMainColorNames.ts+++ b/packages/twenty-ui/design-tokens/pipeline/buildMainColorNames.ts@@ -6,7 +6,7 @@ export const buildMainColorNames = (): string => `${GENERATED_TYPESCRIPT_HEADER}export type ThemeColor = ${colorNames.map(quoteSingle).join(' | ')};-export const MAIN_COLOR_NAMES: ThemeColor[] = [+export const MAIN_COLOR_NAMES: [ThemeColor, ...ThemeColor[]] = [${colorNames.map((colorName) => ` ${quoteSingle(colorName)},`).join('\n')}];`;diff --git a/packages/twenty-ui/design-tokens/pipeline/buildThemeCommon.ts b/packages/twenty-ui/design-tokens/pipeline/buildThemeCommon.tsindex c127eeea5e8..f6356f1501a 100644--- a/packages/twenty-ui/design-tokens/pipeline/buildThemeCommon.ts+++ b/packages/twenty-ui/design-tokens/pipeline/buildThemeCommon.ts@@ -9,7 +9,10 @@ export const buildThemeCommon = ({leaves: CollectedTokenLeaf[];rootKeys: readonly string[];}): string => {- const commonLeaves = leaves.filter((leaf) => rootKeys.includes(leaf.path[0]));+ const commonLeaves = leaves.filter((leaf) => {+ const [rootSegment] = leaf.path;+ return rootSegment !== undefined && rootKeys.includes(rootSegment);+ });const missingRootKey = rootKeys.find((rootKey) => !commonLeaves.some((leaf) => leaf.path[0] === rootKey),);diff --git a/packages/twenty-ui/design-tokens/pipeline/collectLeaves.ts b/packages/twenty-ui/design-tokens/pipeline/collectLeaves.tsindex c8da39e423f..032584eff1d 100644--- a/packages/twenty-ui/design-tokens/pipeline/collectLeaves.ts+++ b/packages/twenty-ui/design-tokens/pipeline/collectLeaves.ts@@ -13,8 +13,7 @@ const collectLeavesUnderPath = (path: string[],): CollectedTokenLeaf[] => {const leaves: CollectedTokenLeaf[] = [];- for (const key of Object.keys(node)) {- const value = node[key];+ for (const [key, value] of Object.entries(node)) {const valuePath = [...path, key];if (isLeaf(value)) {leaves.push({diff --git a/packages/twenty-ui/design-tokens/pipeline/selectSquircleDoubledRadiusLeaves.ts b/packages/twenty-ui/design-tokens/pipeline/selectSquircleDoubledRadiusLeaves.tsindex 6ad71244d11..b9f1b3dbc2c 100644--- a/packages/twenty-ui/design-tokens/pipeline/selectSquircleDoubledRadiusLeaves.ts+++ b/packages/twenty-ui/design-tokens/pipeline/selectSquircleDoubledRadiusLeaves.ts@@ -1,7 +1,9 @@import { ROUND_RADIUS_TOKENS } from '../roundRadiusTokens';import { type CollectedTokenLeaf } from '../types/CollectedTokenLeaf';-const isRadiusLeaf = (leaf: CollectedTokenLeaf): boolean =>+type RadiusLeaf = CollectedTokenLeaf & { path: [string, string, string] };++const isRadiusLeaf = (leaf: CollectedTokenLeaf): leaf is RadiusLeaf =>leaf.path.length === 3 &&leaf.path[0] === 'border' &&leaf.path[1] === 'radius';diff --git a/packages/twenty-ui/design-tokens/pipeline/serializeTree.ts b/packages/twenty-ui/design-tokens/pipeline/serializeTree.tsindex 01d909bed5c..310d46b22cd 100644--- a/packages/twenty-ui/design-tokens/pipeline/serializeTree.ts+++ b/packages/twenty-ui/design-tokens/pipeline/serializeTree.ts@@ -11,8 +11,7 @@ export const serializeTree = ({depth?: number;}): string => {const spaces = ' '.repeat(depth + 1);- const entries = Object.keys(node).map((key) => {- const value = node[key];+ const entries = Object.entries(node).map(([key, value]) => {const serializedValue =typeof value === 'string'? valuediff --git a/packages/twenty-ui/docs/extractDocumentationExamples.ts b/packages/twenty-ui/docs/extractDocumentationExamples.tsindex a6df5c04ab7..8d5f636a51e 100644--- a/packages/twenty-ui/docs/extractDocumentationExamples.ts+++ b/packages/twenty-ui/docs/extractDocumentationExamples.ts@@ -41,10 +41,12 @@ export const extractDocumentationExamples = (const opening = FENCE_OPENING_PATTERN.exec(line);if (opening) {+ const [, indentation = '', marker = '', language = ''] = opening;+openFence = {- indentation: opening[1].length,- marker: opening[2],- language: opening[3].toLowerCase(),+ indentation: indentation.length,+ marker,+ language: language.toLowerCase(),codeLines: [],};}diff --git a/packages/twenty-ui/src/components/code-editor/CodeEditor/utils/getBaseCodeEditorTheme.ts b/packages/twenty-ui/src/components/code-editor/CodeEditor/utils/getBaseCodeEditorTheme.tsindex ab9f57110cd..feb036a5926 100644--- a/packages/twenty-ui/src/components/code-editor/CodeEditor/utils/getBaseCodeEditorTheme.ts+++ b/packages/twenty-ui/src/components/code-editor/CodeEditor/utils/getBaseCodeEditorTheme.ts@@ -13,6 +13,9 @@ const convertColorToHex = (color: string): string => {if (isDefined(displayP3Match)) {const [, r, g, b, a] = displayP3Match;+ if (!isDefined(r) || !isDefined(g) || !isDefined(b)) {+ return color;+ }const rHex = Math.round(parseFloat(r) * 255).toString(16).padStart(2, '0');diff --git a/packages/twenty-ui/src/components/data-display/TintedIconTile/internal/utils/getColorFromTheme.ts b/packages/twenty-ui/src/components/data-display/TintedIconTile/internal/utils/getColorFromTheme.tsindex bfe964917bd..ba537f3ade0 100644--- a/packages/twenty-ui/src/components/data-display/TintedIconTile/internal/utils/getColorFromTheme.ts+++ b/packages/twenty-ui/src/components/data-display/TintedIconTile/internal/utils/getColorFromTheme.ts@@ -5,10 +5,6 @@ export const getColorFromTheme = (shade: number,): string => {const colorMap = themeCssVariables.color as unknown as Record<string, string>;- const tagText = themeCssVariables.tag.text as unknown as Record<- string,- string- >;const key = `${themeColor}${shade}`;- return colorMap[key] ?? tagText[themeColor];+ return colorMap[key] ?? themeCssVariables.tag.text[themeColor];};diff --git a/packages/twenty-ui/src/components/feedback/Toast/__tests__/ToastProvider.test.tsx b/packages/twenty-ui/src/components/feedback/Toast/__tests__/ToastProvider.test.tsxindex 6450f19bb42..0bf5ea2e99f 100644--- a/packages/twenty-ui/src/components/feedback/Toast/__tests__/ToastProvider.test.tsx+++ b/packages/twenty-ui/src/components/feedback/Toast/__tests__/ToastProvider.test.tsx@@ -42,7 +42,7 @@ it('isolates nested provider queues and deduplication', () => {});expect(result.current.toasts).toHaveLength(1);- expect(result.current.toasts[0].notification.children).toBe(+ expect(result.current.toasts[0]?.notification.children).toBe('Child notification',);diff --git a/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToast.test.tsx b/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToast.test.tsxindex d3a6f3c7bfa..208929a7bd2 100644--- a/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToast.test.tsx+++ b/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToast.test.tsx@@ -96,7 +96,7 @@ it('retains a dismissed toast until its exit finishes and calls onClose once', (result.current.closeToast(id);const [closingToast] = store.state.toasts;- expect(closingToast.status).toBe('closing');+ expect(closingToast?.status).toBe('closing');expect(onClose).toHaveBeenCalledOnce();result.current.closeToast(id);@@ -104,7 +104,7 @@ it('retains a dismissed toast until its exit finishes and calls onClose once', (expect(onClose).toHaveBeenCalledOnce();expect(listener).toHaveBeenCalledTimes(2);- completeToastExit({ store, toast: closingToast });+ completeToastExit({ store, toast: closingToast! });expect(store.state.toasts).toEqual([]);expect(onClose).toHaveBeenCalledOnce();expect(listener).toHaveBeenCalledTimes(3);@@ -179,14 +179,14 @@ it('reopens a dismissed toast with a new id and completes each exit independentlexpect(restoredId).not.toBe(firstId);result.current.closeToast(firstId);expect(store.state.toasts).toBe(restoredToasts);- completeToastExit({ store, toast: firstExit });- expect(store.state.toasts[1].notification.children).toBe('Restored');+ completeToastExit({ store, toast: firstExit! });+ expect(store.state.toasts[1]?.notification.children).toBe('Restored');result.current.closeToast(restoredId);const snapshot = store.state.toasts;- completeToastExit({ store, toast: firstExit });+ completeToastExit({ store, toast: firstExit! });expect(store.state.toasts).toBe(snapshot);- completeToastExit({ store, toast: snapshot[1] });+ completeToastExit({ store, toast: snapshot[1]! });expect(store.state.toasts.map(({ notification }) => notification.id)).toEqual([secondId],);@@ -296,7 +296,7 @@ it('ignores unknown dismissals and completion for visible notifications', () =>const snapshot = store.state.toasts;result.current.closeToast('unknown');- completeToastExit({ store, toast: snapshot[0] });+ completeToastExit({ store, toast: snapshot[0]! });expect(store.state.toasts).toBe(snapshot);expect(listener).toHaveBeenCalledOnce();diff --git a/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToastEntries.test.tsx b/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToastEntries.test.tsxindex 4b8a97a403b..db730d9b6a9 100644--- a/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToastEntries.test.tsx+++ b/packages/twenty-ui/src/components/feedback/Toast/hooks/__tests__/useToastEntries.test.tsx@@ -39,7 +39,7 @@ it('rerenders only toast subscribers when the toast list changes', () => {actions.result.current.enqueueToast({ children: 'Saved' });});- expect(entries.result.current[0].notification.children).toBe('Saved');+ expect(entries.result.current[0]?.notification.children).toBe('Saved');expect(renderEntries.mock.calls.length).toBeGreaterThan(initialEntriesRenderCount,);diff --git a/packages/twenty-ui/src/components/feedback/Toaster/__stories__/Toaster.stories.tsx b/packages/twenty-ui/src/components/feedback/Toaster/__stories__/Toaster.stories.tsxindex 0758baa6a5c..65099cd2716 100644--- a/packages/twenty-ui/src/components/feedback/Toaster/__stories__/Toaster.stories.tsx+++ b/packages/twenty-ui/src/components/feedback/Toaster/__stories__/Toaster.stories.tsx@@ -212,7 +212,7 @@ export const RendererRemountDuringExit: Story = {expect(region.getAnimations({ subtree: true })).toHaveLength(0),);await userEvent.click(- within(region).getAllByRole('button', { name: 'Close' })[0],+ within(region).getAllByRole('button', { name: 'Close' })[0]!,);await userEvent.click(canvas.getByRole('button', { name: 'Enter workspace' }),@@ -376,7 +376,11 @@ export const StackReflow: Story = {await waitFor(() =>expect(region.getAnimations({ subtree: true })).toHaveLength(0),);- const [first, middle, last] = body.getAllByRole('status');+ const statuses = body.getAllByRole('status');+ expect(statuses).toHaveLength(3);+ const first = statuses[0]!;+ const middle = statuses[1]!;+ const last = statuses[2]!;const firstTop = first.getBoundingClientRect().top;const gap = middle.getBoundingClientRect().top - firstTop;const isTopAnchored = getComputedStyle(region).top === '0px';@@ -424,7 +428,11 @@ export const ReopenDuringExit: Story = {await waitFor(() =>expect(region.getAnimations({ subtree: true })).toHaveLength(0),);- const [toast, secondToast, thirdToast] = body.getAllByRole('status');+ const statuses = body.getAllByRole('status');+ expect(statuses).toHaveLength(3);+ const toast = statuses[0]!;+ const secondToast = statuses[1]!;+ const thirdToast = statuses[2]!;const id = toast.id;await userEvent.click(within(toast).getByRole('button', { name: 'Close' }));if (isMotionEnabled()) {@@ -439,7 +447,7 @@ export const ReopenDuringExit: Story = {restoredToasts.slice(0, 2).map((notification) => notification.id),).toEqual([secondToast.id, thirdToast.id]);expect(toast).not.toBeInTheDocument();- expect(restoredToasts[2].id).not.toBe(id);+ expect(restoredToasts[2]?.id).not.toBe(id);expect(restoredToasts[2]).toHaveTextContent('Already saved');expect(restoredToasts[2]).toBeVisible();expect(args.onClose).toHaveBeenCalledOnce();diff --git a/packages/twenty-ui/src/components/input/IconButton/__stories__/IconButton.stories.tsx b/packages/twenty-ui/src/components/input/IconButton/__stories__/IconButton.stories.tsxindex e37dd204d4a..c58f1072e9a 100644--- a/packages/twenty-ui/src/components/input/IconButton/__stories__/IconButton.stories.tsx+++ b/packages/twenty-ui/src/components/input/IconButton/__stories__/IconButton.stories.tsx@@ -310,7 +310,7 @@ export const Catalog: CatalogStory<Story, typeof IconButton> = {{name: 'state',values: Object.keys(CATALOG_STATES),- props: (state: string) => CATALOG_STATES[state],+ props: (state: string) => CATALOG_STATES[state] ?? {},},{name: 'color',diff --git a/packages/twenty-ui/src/components/input/LightButton/__stories__/LightButton.stories.tsx b/packages/twenty-ui/src/components/input/LightButton/__stories__/LightButton.stories.tsxindex fa07edf9649..b8897ecbe0f 100644--- a/packages/twenty-ui/src/components/input/LightButton/__stories__/LightButton.stories.tsx+++ b/packages/twenty-ui/src/components/input/LightButton/__stories__/LightButton.stories.tsx@@ -122,7 +122,7 @@ export const Catalog: CatalogStory<Story, typeof LightButton> = {{name: 'state',values: Object.keys(CATALOG_STATES),- props: (state: string) => CATALOG_STATES[state],+ props: (state: string) => CATALOG_STATES[state] ?? {},},{name: 'emphasis',diff --git a/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButton.stories.tsx b/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButton.stories.tsxindex 6d4323c8a78..edf0c453ba0 100644--- a/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButton.stories.tsx+++ b/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButton.stories.tsx@@ -128,7 +128,7 @@ export const Catalog: CatalogStory<Story, typeof LightIconButton> = {{name: 'state',values: Object.keys(CATALOG_STATES),- props: (state: string) => CATALOG_STATES[state],+ props: (state: string) => CATALOG_STATES[state] ?? {},},{name: 'emphasis',diff --git a/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButtonGroups.stories.tsx b/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButtonGroups.stories.tsxindex aaf7cc0c409..869eb93eea4 100644--- a/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButtonGroups.stories.tsx+++ b/packages/twenty-ui/src/components/input/LightIconButton/__stories__/LightIconButtonGroups.stories.tsx@@ -59,8 +59,8 @@ export const Framed: Story = {).toBeGreaterThan(0);}await expect(- buttons[1].getBoundingClientRect().left -- buttons[0].getBoundingClientRect().right,+ buttons[1]!.getBoundingClientRect().left -+ buttons[0]!.getBoundingClientRect().right,).toBe(2);},};diff --git a/packages/twenty-ui/src/components/input/MainButton/__stories__/MainButton.stories.tsx b/packages/twenty-ui/src/components/input/MainButton/__stories__/MainButton.stories.tsxindex d655e5512c5..2a1e3188035 100644--- a/packages/twenty-ui/src/components/input/MainButton/__stories__/MainButton.stories.tsx+++ b/packages/twenty-ui/src/components/input/MainButton/__stories__/MainButton.stories.tsx@@ -114,7 +114,7 @@ export const Catalog: CatalogStory<Story, typeof MainButton> = {{name: 'state',values: Object.keys(CATALOG_STATES),- props: (state: string) => CATALOG_STATES[state],+ props: (state: string) => CATALOG_STATES[state] ?? {},},{name: 'variant',diff --git a/packages/twenty-ui/src/components/layout/AnimatedIconCrossfade/__stories__/AnimatedIconCrossfade.stories.tsx b/packages/twenty-ui/src/components/layout/AnimatedIconCrossfade/__stories__/AnimatedIconCrossfade.stories.tsxindex 140d19bc213..eae46db5a7b 100644--- a/packages/twenty-ui/src/components/layout/AnimatedIconCrossfade/__stories__/AnimatedIconCrossfade.stories.tsx+++ b/packages/twenty-ui/src/components/layout/AnimatedIconCrossfade/__stories__/AnimatedIconCrossfade.stories.tsx@@ -47,7 +47,9 @@ export const AnimatedIcon: Story = {});await document.fonts.load('500 1em Inter');await document.fonts.ready;- const [pencil, cross] = button.querySelectorAll('svg');+ const icons = button.querySelectorAll('svg');+ const pencil = icons[0]!;+ const cross = icons[1]!;const originalWidth = button.getBoundingClientRect().width;await expect(button.getBoundingClientRect().height).toBe(24);diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsxindex 655c43c6875..82772d2c5ee 100644--- a/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx+++ b/packages/twenty-ui/src/components/navigation/Dropdown/__tests__/Dropdown.menu.test.tsx@@ -425,7 +425,7 @@ describe('Dropdown menu', () => {expect(screen.getByRole('menu')).toBeVisible();expect(clickEvents).toHaveLength(1);- expect(clickEvents[0].defaultPrevented).toBe(true);+ expect(clickEvents[0]?.defaultPrevented).toBe(true);});it('lets unhandled modifier shortcuts leave the menu and keeps other keys inside', async () => {diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsxindex 41e95f6d654..9c3eb5946c1 100644--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/DropdownRoot.tsx@@ -93,11 +93,12 @@ export const DropdownRoot = ({};const goBack = () => {- if (pageHistory.length < 2) {+ const previousPage = pageHistory[pageHistory.length - 2];++ if (!isDefined(previousPage)) {return;}- const previousPage = pageHistory[pageHistory.length - 2];const trigger = pageHistory[pageHistory.length - 1]?.trigger;setPageFocusRequest({diff --git a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.tsindex 9402e22a1bf..a962304d938 100644--- a/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts+++ b/packages/twenty-ui/src/components/navigation/Dropdown/internal/getDropdownFocusTarget.ts@@ -31,8 +31,10 @@ export const getDropdownFocusTarget = ({? items.filter((item) => item.dataset.dropdownPage === target.page): [];- if (pageTriggers.length === 1) {- return pageTriggers[0];+ const [firstPageTrigger] = pageTriggers;++ if (pageTriggers.length === 1 && isDefined(firstPageTrigger)) {+ return firstPageTrigger;}const matchingPageTriggers = isNonEmptyString(target?.label)@@ -41,8 +43,13 @@ export const getDropdownFocusTarget = ({): [];- if (matchingPageTriggers.length === 1) {- return matchingPageTriggers[0];+ const [firstMatchingPageTrigger] = matchingPageTriggers;++ if (+ matchingPageTriggers.length === 1 &&+ isDefined(firstMatchingPageTrigger)+ ) {+ return firstMatchingPageTrigger;}const pageTrigger = isDefined(target) ? items[target.index] : undefined;diff --git a/packages/twenty-ui/src/components/navigation/NavigationBar/__stories__/NavigationBar.stories.tsx b/packages/twenty-ui/src/components/navigation/NavigationBar/__stories__/NavigationBar.stories.tsxindex c5508cb5105..cfd300e931b 100644--- a/packages/twenty-ui/src/components/navigation/NavigationBar/__stories__/NavigationBar.stories.tsx+++ b/packages/twenty-ui/src/components/navigation/NavigationBar/__stories__/NavigationBar.stories.tsx@@ -40,7 +40,7 @@ export const Default: Story = {expect(search).toHaveAttribute('aria-pressed', 'false');await userEvent.click(search);- expect(args.items[1].onClick).toHaveBeenCalled();+ expect(args.items[1]?.onClick).toHaveBeenCalled();},};diff --git a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsxindex 5dc6cb3703e..6b90e899589 100644--- a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx+++ b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx@@ -184,7 +184,7 @@ export const Catalog: CatalogStory<Story, typeof Button> = {{name: 'state',values: Object.keys(CATALOG_STATES),- props: (state: string) => CATALOG_STATES[state],+ props: (state: string) => CATALOG_STATES[state] ?? {},},{name: 'color',diff --git a/packages/twenty-ui/src/primitives/input/ButtonGroup/__stories__/ButtonGroup.stories.tsx b/packages/twenty-ui/src/primitives/input/ButtonGroup/__stories__/ButtonGroup.stories.tsxindex 25e4b984c9b..6e1c8653c50 100644--- a/packages/twenty-ui/src/primitives/input/ButtonGroup/__stories__/ButtonGroup.stories.tsx+++ b/packages/twenty-ui/src/primitives/input/ButtonGroup/__stories__/ButtonGroup.stories.tsx@@ -32,7 +32,7 @@ export const Default: Story = {play: async ({ canvasElement }) => {const canvas = within(canvasElement);const buttons = canvas.getAllByRole('button');- buttons[0].focus();+ buttons[0]!.focus();await userEvent.tab();await expect(buttons[1]).toHaveFocus();},@@ -144,8 +144,8 @@ export const FramedAttached: Story = {play: async ({ canvasElement }) => {const canvas = within(canvasElement);const buttons = canvas.getAllByRole('button');- const firstButtonStyle = getComputedStyle(buttons[0]);- const lastButtonStyle = getComputedStyle(buttons[2]);+ const firstButtonStyle = getComputedStyle(buttons[0]!);+ const lastButtonStyle = getComputedStyle(buttons[2]!);const groupStyle = getComputedStyle(canvas.getByRole('group'));await expect(firstButtonStyle.borderStartEndRadius).toBe('0px');diff --git a/packages/twenty-ui/src/theme/__tests__/getNextThemeColor.test.ts b/packages/twenty-ui/src/theme/__tests__/getNextThemeColor.test.tsindex b8b126433be..a4a4859a27b 100644--- a/packages/twenty-ui/src/theme/__tests__/getNextThemeColor.test.ts+++ b/packages/twenty-ui/src/theme/__tests__/getNextThemeColor.test.ts@@ -8,14 +8,14 @@ import { getNextThemeColor } from '../getNextThemeColor';describe('getNextThemeColor', () => {it('returns the next theme color', () => {const currentColor: ThemeColor = MAIN_COLOR_NAMES[0];- const nextColor: ThemeColor = MAIN_COLOR_NAMES[1];+ const nextColor: ThemeColor = MAIN_COLOR_NAMES[1]!;expect(getNextThemeColor(MAIN_COLOR_NAMES, currentColor)).toBe(nextColor);});it('returns the first color when reaching the end', () => {const currentColor: ThemeColor =- MAIN_COLOR_NAMES[MAIN_COLOR_NAMES.length - 1];+ MAIN_COLOR_NAMES[MAIN_COLOR_NAMES.length - 1]!;const nextColor: ThemeColor = MAIN_COLOR_NAMES[0];expect(getNextThemeColor(MAIN_COLOR_NAMES, currentColor)).toBe(nextColor);diff --git a/packages/twenty-ui/src/theme/constants/MainColorNames.ts b/packages/twenty-ui/src/theme/constants/MainColorNames.tsindex a054f836d63..d1e261a0e34 100644--- a/packages/twenty-ui/src/theme/constants/MainColorNames.ts+++ b/packages/twenty-ui/src/theme/constants/MainColorNames.ts@@ -27,7 +27,7 @@ export type ThemeColor =| 'brown'| 'gray';-export const MAIN_COLOR_NAMES: ThemeColor[] = [+export const MAIN_COLOR_NAMES: [ThemeColor, ...ThemeColor[]] = ['red','ruby','crimson',diff --git a/packages/twenty-ui/src/theme/getNextThemeColor.ts b/packages/twenty-ui/src/theme/getNextThemeColor.tsindex 7cdcc7ba9a9..03aa61ca450 100644--- a/packages/twenty-ui/src/theme/getNextThemeColor.ts+++ b/packages/twenty-ui/src/theme/getNextThemeColor.ts@@ -1,15 +1,16 @@import { type ThemeColor } from '@ui/theme/constants/MainColorNames';export const getNextThemeColor = (- colorNames: ThemeColor[],+ colorNames: [ThemeColor, ...ThemeColor[]],currentColor?: ThemeColor,): ThemeColor => {+ const [firstColor] = colorNames;if (currentColor === null || currentColor === undefined) {- return colorNames[0];+ return firstColor;}const currentColorIndex = colorNames.findIndex((color) => color === currentColor,);const nextColorIndex = (currentColorIndex + 1) % colorNames.length;- return colorNames[nextColorIndex];+ return colorNames[nextColorIndex] ?? firstColor;};diff --git a/packages/twenty-ui/src/utilities/color/utils/stringToThemeColorP3String.ts b/packages/twenty-ui/src/utilities/color/utils/stringToThemeColorP3String.tsindex f144cf0ac89..f68e3adef8c 100644--- a/packages/twenty-ui/src/utilities/color/utils/stringToThemeColorP3String.ts+++ b/packages/twenty-ui/src/utilities/color/utils/stringToThemeColorP3String.ts@@ -12,7 +12,7 @@ export const stringToThemeColor = (string: string): ThemeColor => {}const colorIndex = Math.abs(hash) % MAIN_COLOR_NAMES.length;- return MAIN_COLOR_NAMES[colorIndex];+ return MAIN_COLOR_NAMES[colorIndex] ?? MAIN_COLOR_NAMES[0];};export const stringToThemeColorP3String = ({diff --git a/packages/twenty-ui/src/utilities/color/utils/themeColorSchema.ts b/packages/twenty-ui/src/utilities/color/utils/themeColorSchema.tsindex 8b2bde570ce..2b726780e2c 100644--- a/packages/twenty-ui/src/utilities/color/utils/themeColorSchema.ts+++ b/packages/twenty-ui/src/utilities/color/utils/themeColorSchema.ts@@ -1,7 +1,5 @@import { z } from 'zod';-import { type ThemeColor, MAIN_COLOR_NAMES } from '@ui/theme';+import { MAIN_COLOR_NAMES } from '@ui/theme';-export const themeColorSchema = z.enum(- MAIN_COLOR_NAMES as [ThemeColor, ...ThemeColor[]],-);+export const themeColorSchema = z.enum(MAIN_COLOR_NAMES);diff --git a/packages/twenty-ui/tsconfig.json b/packages/twenty-ui/tsconfig.jsonindex 1695faee298..a2e0b1a41b9 100644--- a/packages/twenty-ui/tsconfig.json+++ b/packages/twenty-ui/tsconfig.json@@ -7,6 +7,7 @@"allowSyntheticDefaultImports": true,"strict": true,"moduleResolution": "bundler",+ "noUncheckedIndexedAccess": true,"esModuleInterop": true,"noEmit": true,"types": ["node", "vitest/globals"],