From d4504f108058e667afeddf38c4ff9d3dcf0d1e5b Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Thu, 20 Apr 2023 12:00:48 +0200 Subject: [PATCH] Build: Migrate @storybook/addon-backgrounds to strict-ts --- .../backgrounds/src/containers/BackgroundSelector.tsx | 6 +++--- code/addons/backgrounds/src/helpers/index.ts | 8 ++++---- code/addons/backgrounds/src/types/index.ts | 2 +- code/addons/backgrounds/tsconfig.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/addons/backgrounds/src/containers/BackgroundSelector.tsx b/code/addons/backgrounds/src/containers/BackgroundSelector.tsx index 078a2752a5e3..d941f178b788 100644 --- a/code/addons/backgrounds/src/containers/BackgroundSelector.tsx +++ b/code/addons/backgrounds/src/containers/BackgroundSelector.tsx @@ -18,10 +18,10 @@ import { getBackgroundColorByName } from '../helpers'; const createBackgroundSelectorItem = memoize(1000)( ( - id: string, + id: string | null, name: string, value: string, - hasSwatch: boolean, + hasSwatch: boolean | null, change: (arg: { selected: string; name: string }) => void, active: boolean ): BackgroundSelectorItem => ({ @@ -102,7 +102,7 @@ export const BackgroundSelector: FC = memo(function BackgroundSelector() { } const onBackgroundChange = useCallback( - (value: string) => { + (value: string | undefined) => { updateGlobals({ [BACKGROUNDS_PARAM_KEY]: { ...globals[BACKGROUNDS_PARAM_KEY], value } }); }, [backgroundsConfig, globals, updateGlobals] diff --git a/code/addons/backgrounds/src/helpers/index.ts b/code/addons/backgrounds/src/helpers/index.ts index 39065eec6648..c1af13cde407 100644 --- a/code/addons/backgrounds/src/helpers/index.ts +++ b/code/addons/backgrounds/src/helpers/index.ts @@ -15,7 +15,7 @@ export const isReduceMotionEnabled = () => { export const getBackgroundColorByName = ( currentSelectedValue: string, backgrounds: Background[] = [], - defaultName: string + defaultName: string | null | undefined ): string => { if (currentSelectedValue === 'transparent') { return 'transparent'; @@ -52,7 +52,7 @@ export const clearStyles = (selector: string | string[]) => { const clearStyle = (selector: string) => { const element = document.getElementById(selector) as HTMLElement; if (element) { - element.parentElement.removeChild(element); + element.parentElement?.removeChild(element); } }; @@ -70,7 +70,7 @@ export const addGridStyle = (selector: string, css: string) => { } }; -export const addBackgroundStyle = (selector: string, css: string, storyId: string) => { +export const addBackgroundStyle = (selector: string, css: string, storyId: string | null) => { const existingStyle = document.getElementById(selector) as HTMLElement; if (existingStyle) { if (existingStyle.innerHTML !== css) { @@ -85,7 +85,7 @@ export const addBackgroundStyle = (selector: string, css: string, storyId: strin // If grids already exist, we want to add the style tag BEFORE it so the background doesn't override grid const existingGridStyle = document.getElementById(gridStyleSelector) as HTMLElement; if (existingGridStyle) { - existingGridStyle.parentElement.insertBefore(style, existingGridStyle); + existingGridStyle.parentElement?.insertBefore(style, existingGridStyle); } else { document.head.appendChild(style); } diff --git a/code/addons/backgrounds/src/types/index.ts b/code/addons/backgrounds/src/types/index.ts index f1f0285ac319..1439f4cd1329 100644 --- a/code/addons/backgrounds/src/types/index.ts +++ b/code/addons/backgrounds/src/types/index.ts @@ -20,7 +20,7 @@ export interface Background { } export interface BackgroundsParameter { - default?: string; + default?: string | null; disable?: boolean; values: Background[]; } diff --git a/code/addons/backgrounds/tsconfig.json b/code/addons/backgrounds/tsconfig.json index 4c6f20a1be4d..b5a2f9a70918 100644 --- a/code/addons/backgrounds/tsconfig.json +++ b/code/addons/backgrounds/tsconfig.json @@ -2,6 +2,6 @@ "extends": "../../tsconfig.json", "include": ["src/**/*"], "compilerOptions": { - "strict": false + "strict": true } }