fix: simplify deepKeys type to fix checks

This commit is contained in:
tglide
2023-08-11 12:35:04 +01:00
parent 75c73ee176
commit 29f709316c
3 changed files with 12 additions and 7 deletions
-5
View File
@@ -1,10 +1,5 @@
import type { Writable } from 'svelte/store';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type DeepKeys<T extends Record<string, any>> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[K in keyof T]: T[K] extends Record<string, any> ? `${K}.${DeepKeys<T[K]>}` : K;
}[keyof T];
export type WritableValue<T> = T extends Writable<infer U> ? U : never;
export function isHTMLElement(el: unknown): el is HTMLElement {
+1
View File
@@ -20,6 +20,7 @@ const initialFormData = {
root: false
}
};
export type MigrationFormData = typeof initialFormData;
export const createMigrationFormStore = () => {
@@ -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<typeof createMigrationFormStore>;
export let provider: ReturnType<typeof createMigrationProviderStore>;
type ValueOf<T> = T[keyof T];
type FormData = WritableValue<typeof formData>;
type FormKeys = DeepKeys<FormData>;
// 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;
}>;
}>;
/**
*