diff --git a/src/lib/helpers/types.ts b/src/lib/helpers/types.ts index 5c5ffec06d..7f054f210c 100644 --- a/src/lib/helpers/types.ts +++ b/src/lib/helpers/types.ts @@ -1,10 +1,5 @@ import type { Writable } from 'svelte/store'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export type DeepKeys> = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [K in keyof T]: T[K] extends Record ? `${K}.${DeepKeys}` : K; -}[keyof T]; export type WritableValue = T extends Writable ? U : never; export function isHTMLElement(el: unknown): el is HTMLElement { diff --git a/src/lib/stores/migration.ts b/src/lib/stores/migration.ts index 953f7b6955..857e09f1a4 100644 --- a/src/lib/stores/migration.ts +++ b/src/lib/stores/migration.ts @@ -20,6 +20,7 @@ const initialFormData = { root: false } }; + export type MigrationFormData = typeof initialFormData; export const createMigrationFormStore = () => { diff --git a/src/routes/console/(migration-wizard)/resource-form.svelte b/src/routes/console/(migration-wizard)/resource-form.svelte index 07c7c5ec93..531aa6e246 100644 --- a/src/routes/console/(migration-wizard)/resource-form.svelte +++ b/src/routes/console/(migration-wizard)/resource-form.svelte @@ -2,7 +2,7 @@ import { EyebrowHeading } from '$lib/components'; import { Button } from '$lib/elements/forms'; import { deepMap } from '$lib/helpers/object'; - import type { DeepKeys, WritableValue } from '$lib/helpers/types'; + import type { WritableValue } from '$lib/helpers/types'; import { sdk } from '$lib/stores/sdk'; import { onMount } from 'svelte'; @@ -19,8 +19,17 @@ export let formData: ReturnType; export let provider: ReturnType; + type ValueOf = T[keyof T]; type FormData = WritableValue; - type FormKeys = DeepKeys; + // TL;DR of this type: It gets a object with two levels (in this case FormData) + // And returns a join of the keys with a dot between them. + // e.g. If FormData was { users: { root: boolean, teams: boolean } } + // The type would be 'users.root' | 'users.teams' + type FormKeys = ValueOf<{ + [K in keyof FormData]: ValueOf<{ + [L in keyof FormData[K]]: L extends string ? `${K}.${L}` : never; + }>; + }>; /** *