Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Oct 9, 2024
1 parent b8a8451 commit 5db9860
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions resources/js/Pages/Artists/Components/Form/PhotoForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import type { EditPhotoResource, ArtistPhotoCrop } from '@/types/artists';
import Cropper, { type CropValue } from '@/Components/Cropper.svelte';
import Label from '@/Components/Form/Label.svelte';
import type { Writable } from 'svelte/store';

Check warning on line 8 in resources/js/Pages/Artists/Components/Form/PhotoForm.svelte

View workflow job for this annotation

GitHub Actions / Lint

`svelte/store` type import should occur before import of `@inertiajs/svelte`
let { currentPhoto, form }: {
currentPhoto: EditPhotoResource | null;
form: InertiaForm<{
form: Writable<InertiaForm<{
photo: {
file: File | null;
url: string | null;
Expand All @@ -17,7 +18,7 @@
source: string | null;
grayscale: boolean;
};
}>;
}>>;
} = $props();
let activePicker: Picker = $state({ type: 'current' });
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Pages/Tales/Components/Form/ActorsForm.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import { tick } from 'svelte';
import type { Writable } from 'svelte/store';
import { type InertiaForm } from '@inertiajs/svelte';
import randomKey from '@/helpers/randomKey';
import ArtistPicker from '@/Components/ComboBox/ArtistPicker.svelte';
let { form }: {
form: InertiaForm<{
form: Writable<InertiaForm<{
actors: Array<{
artist: string;
characters: string | null;
Expand All @@ -15,7 +16,7 @@
noTransitions: boolean;
hasDeletedElement: null | 'above' | 'below';
}>;
}>;
}>>;
} = $props();
function addActor() {
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Pages/Tales/Components/Form/CoverForm.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<script lang="ts">
import type { Writable } from 'svelte/store';
import { type InertiaForm } from '@inertiajs/svelte';
import prettyBytes from 'pretty-bytes';
import type { CoverResource } from '@/types/tales';
import Label from '@/Components/Form/Label.svelte';
let { currentCover, form, action }: {
currentCover: CoverResource | null;
form: InertiaForm<{
form: Writable<InertiaForm<{
removeCover: boolean;
cover: File | null;
}>;
}>>;
action: 'create' | 'edit';
} = $props();
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Pages/Tales/Components/Form/CreditsForm.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<script lang="ts">
import type { Writable } from 'svelte/store';
import { type InertiaForm } from '@inertiajs/svelte';
import type { CreditType } from '@/types/tales';
import { creditLabels } from '@/helpers/creditLabels';
import randomKey from '@/helpers/randomKey';
import ArtistPicker from '@/Components/ComboBox/ArtistPicker.svelte';
let { form }: {
form: InertiaForm<{
form: Writable<InertiaForm<{
credits: Array<{
artist: string;
type: CreditType;
as: string | null;
nr: number | null;
key: string;
}>;
}>;
}>>;
} = $props();
function addCredit() {
Expand Down
8 changes: 4 additions & 4 deletions resources/js/types/inertia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ declare module '@inertiajs/svelte' {
>;
export const page: Readable<Page>;
export function remember<T>(initialState: T, key: string): Writable<T>;
export function useForm<TForm extends FormDataType>(data: TForm | (() => TForm)): InertiaForm<TForm>;
export function useForm<TForm extends FormDataType>(data: TForm | (() => TForm)): Writable<InertiaForm<TForm>>;
export function useForm<TForm extends FormDataType>(
rememberKey: string,
data: TForm | (() => TForm),
): InertiaForm<TForm>;
): Writable<InertiaForm<TForm>>;
export function useForm<TForm extends FormDataType>(
rememberKeyOrData: string | TForm | (() => TForm),
maybeData?: TForm | (() => TForm),
): InertiaForm<TForm>;
): Writable<InertiaForm<TForm>>;

type FormDataType = object;

Expand Down Expand Up @@ -73,5 +73,5 @@ declare module '@inertiajs/svelte' {
cancel(): void;
}

export type InertiaForm<TForm extends FormDataType> = Writable<TForm & InertiaFormProps<TForm>>;
export type InertiaForm<TForm extends FormDataType> = TForm & InertiaFormProps<TForm>;
}

0 comments on commit 5db9860

Please sign in to comment.