Skip to content

Commit

Permalink
fix(types): update TypeScript definitions for Svelte 4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed May 15, 2024
1 parent 3cc2c78 commit f308d9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
18 changes: 12 additions & 6 deletions src/Pincode.svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";
import type { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";

export type Code = string[];

export interface PincodeProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> {
type RestProps = SvelteHTMLElements["div"];

export interface PincodeProps extends RestProps {
/**
* @default []
*/
Expand All @@ -29,6 +31,8 @@ export interface PincodeProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNa
* @default false
*/
selectTextOnFocus?: boolean;

[key: `data-${string}`]: any;
}

export default class Pincode extends SvelteComponentTyped<
Expand All @@ -39,7 +43,9 @@ export default class Pincode extends SvelteComponentTyped<
},
{ default: {} }
> {
focusFirstInput?: () => void;
focusNextEmptyInput?: () => void;
focusLastInput?: () => void;
focusFirstInput: () => void;

focusNextEmptyInput: () => void;

focusLastInput: () => void;
}
16 changes: 12 additions & 4 deletions src/PincodeInput.svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";
import type { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";

export interface PincodeInputProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["input"]> {
type RestProps = SvelteHTMLElements["input"];

export interface PincodeInputProps extends RestProps {
/**
* @default ""
*/
Expand All @@ -16,10 +18,16 @@ export interface PincodeInputProps extends svelte.JSX.HTMLAttributes<HTMLElement
* @default null
*/
ref?: null | HTMLInputElement;

[key: `data-${string}`]: any;
}

export default class PincodeInput extends SvelteComponentTyped<
PincodeInputProps,
{ focus: WindowEventMap["focus"]; blur: WindowEventMap["blur"]; keydown: WindowEventMap["keydown"] },
{
focus: WindowEventMap["focus"];
blur: WindowEventMap["blur"];
keydown: WindowEventMap["keydown"];
},
{}
> {}
6 changes: 3 additions & 3 deletions test/Pincode.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
$: error = complete && !success;
onMount(() => {
ref.focusFirstInput?.();
ref.focusNextEmptyInput?.();
ref.focusLastInput?.();
ref.focusFirstInput();
ref.focusNextEmptyInput();
ref.focusLastInput();
});
</script>

Expand Down

0 comments on commit f308d9e

Please sign in to comment.