mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Merge pull request #502 from appwrite/dewizardify-types
fix: simplify deepKeys type to fix checks
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}>;
|
||||
}>;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user