Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: simplify deepKeys type to fix checks #502

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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