From a81b40504f3e6cb135985616690169b34e962db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 15 Mar 2024 20:18:59 +0100 Subject: [PATCH 1/6] refactor(addons/actions): resolve ts-expect-error --- code/addons/actions/src/runtime/action.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/addons/actions/src/runtime/action.ts b/code/addons/actions/src/runtime/action.ts index a647a8eb0d1b..fab9e8aae1d4 100644 --- a/code/addons/actions/src/runtime/action.ts +++ b/code/addons/actions/src/runtime/action.ts @@ -21,10 +21,9 @@ const isReactSyntheticEvent = (e: unknown): e is SyntheticEvent => findProto(e, (proto) => /^Synthetic(?:Base)?Event$/.test(proto.constructor.name)) && typeof (e as SyntheticEvent).persist === 'function' ); -const serializeArg = (a: T) => { +const serializeArg = (a: T) => { if (isReactSyntheticEvent(a)) { const e: SyntheticEvent = Object.create( - // @ts-expect-error (Converted from ts-ignore) a.constructor.prototype, Object.getOwnPropertyDescriptors(a) ); From cabfab8a522b0cee3516c641fdfa3139b11541dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 15 Mar 2024 20:26:50 +0100 Subject: [PATCH 2/6] refactor(addons/links): resolve ts-expect-error --- code/addons/links/src/utils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index 51d8c09c5fc4..651183a9df66 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -37,9 +37,7 @@ export const hrefTo = (title: ComponentTitle, name: StoryName): Promise return new Promise((resolve) => { const { location } = document; const query = parseQuery(location.search); - // @ts-expect-error (Converted from ts-ignore) - const existingId = [].concat(query.id)[0]; - // @ts-expect-error (Converted from ts-ignore) + const existingId = query.id; const titleToLink = title || existingId.split('--', 2)[0]; const id = toId(titleToLink, name); const path = `/story/${id}`; From f9979b391d4c2668560b77067e5a77fee7f7cd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 15 Mar 2024 20:39:46 +0100 Subject: [PATCH 3/6] refactor(core): resolve ts-expect-error in js package manager --- .../core-common/src/js-package-manager/JsPackageManager.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/lib/core-common/src/js-package-manager/JsPackageManager.ts b/code/lib/core-common/src/js-package-manager/JsPackageManager.ts index 42a31985047a..046b566df274 100644 --- a/code/lib/core-common/src/js-package-manager/JsPackageManager.ts +++ b/code/lib/core-common/src/js-package-manager/JsPackageManager.ts @@ -17,6 +17,8 @@ const logger = console; export type PackageManagerName = 'npm' | 'yarn1' | 'yarn2' | 'pnpm'; +type StorybookPackage = keyof typeof storybookPackagesVersions; + /** * Extract package name and version from input * @@ -361,7 +363,7 @@ export abstract class JsPackageManager { * * @param packageNames */ - public getVersions(...packageNames: string[]): Promise { + public getVersions(...packageNames: StorybookPackage[]): Promise { return Promise.all( packageNames.map((packageName) => { return this.getVersion(packageName); @@ -378,11 +380,10 @@ export abstract class JsPackageManager { * @param packageName The name of the package * @param constraint A valid semver constraint, example: '1.x || >=2.5.0 || 5.0.0 - 7.2.3' */ - public async getVersion(packageName: string, constraint?: string): Promise { + public async getVersion(packageName: StorybookPackage, constraint?: string): Promise { let current: string | undefined; if (/(@storybook|^sb$|^storybook$)/.test(packageName)) { - // @ts-expect-error (Converted from ts-ignore) current = storybookPackagesVersions[packageName]; } From db4867c03bbb848ad04e7446cd5915d03c641975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 16 Mar 2024 10:15:12 +0100 Subject: [PATCH 4/6] refactor(preview/web): resolve ts-expect-error --- code/lib/preview-api/src/modules/preview-web/Preview.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/lib/preview-api/src/modules/preview-web/Preview.tsx b/code/lib/preview-api/src/modules/preview-web/Preview.tsx index af851edfc304..29ea71045949 100644 --- a/code/lib/preview-api/src/modules/preview-web/Preview.tsx +++ b/code/lib/preview-api/src/modules/preview-web/Preview.tsx @@ -100,9 +100,7 @@ export class Preview { get: (_, method) => { if (this.storyStoreValue) { deprecate('Accessing the Story Store is deprecated and will be removed in 9.0'); - - // @ts-expect-error I'm not sure if there's a way to keep TS happy here - return this.storyStoreValue[method]; + return this.storyStoreValue[method as keyof StoryStore]; } throw new StoryStoreAccessedBeforeInitializationError(); From 5dc3d9232f0e5042c076f8eaa65a4437be6849d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 16 Mar 2024 10:21:39 +0100 Subject: [PATCH 5/6] refactor(test): resolve ts-expect-error --- code/lib/test/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/lib/test/src/index.ts b/code/lib/test/src/index.ts index 600c68f1d3b4..7bd72666f341 100644 --- a/code/lib/test/src/index.ts +++ b/code/lib/test/src/index.ts @@ -36,6 +36,6 @@ const resetAllMocksLoader: LoaderFunction = ({ parameters }) => { } }; -// @ts-expect-error We are using this as a default Storybook loader, when the test package is used. This avoids the need for optional peer dependency workarounds. +// We are using this as a default Storybook loader, when the test package is used. This avoids the need for optional peer dependency workarounds. // eslint-disable-next-line no-underscore-dangle -global.__STORYBOOK_TEST_LOADERS__ = [resetAllMocksLoader]; +(global as any).__STORYBOOK_TEST_LOADERS__ = [resetAllMocksLoader]; From f6688d503bd13f966a76a8b1ef709821cee684d6 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Sat, 16 Mar 2024 12:29:45 +0100 Subject: [PATCH 6/6] Fix type errors --- .../src/js-package-manager/JsPackageManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/lib/core-common/src/js-package-manager/JsPackageManager.ts b/code/lib/core-common/src/js-package-manager/JsPackageManager.ts index 046b566df274..8f306850b032 100644 --- a/code/lib/core-common/src/js-package-manager/JsPackageManager.ts +++ b/code/lib/core-common/src/js-package-manager/JsPackageManager.ts @@ -363,7 +363,7 @@ export abstract class JsPackageManager { * * @param packageNames */ - public getVersions(...packageNames: StorybookPackage[]): Promise { + public getVersions(...packageNames: string[]): Promise { return Promise.all( packageNames.map((packageName) => { return this.getVersion(packageName); @@ -380,11 +380,11 @@ export abstract class JsPackageManager { * @param packageName The name of the package * @param constraint A valid semver constraint, example: '1.x || >=2.5.0 || 5.0.0 - 7.2.3' */ - public async getVersion(packageName: StorybookPackage, constraint?: string): Promise { + public async getVersion(packageName: string, constraint?: string): Promise { let current: string | undefined; - if (/(@storybook|^sb$|^storybook$)/.test(packageName)) { - current = storybookPackagesVersions[packageName]; + if (packageName in storybookPackagesVersions) { + current = storybookPackagesVersions[packageName as StorybookPackage]; } let latest;