Skip to content

Commit

Permalink
Merge pull request #502 from appwrite/dewizardify-types
Browse files Browse the repository at this point in the history
fix: simplify deepKeys type to fix checks
  • Loading branch information
ArmanNik authored Aug 11, 2023
2 parents 75c73ee + 29f7093 commit 532db68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/lib/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const initialFormData = {
root: false
}
};

export type MigrationFormData = typeof initialFormData;

export const createMigrationFormStore = () => {
Expand Down
13 changes: 11 additions & 2 deletions src/routes/console/(migration-wizard)/resource-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}>;
}>;
/**
*
Expand Down

0 comments on commit 532db68

Please sign in to comment.