Skip to content

Instantly share code, notes, and snippets.

@Crisfole
Forked from mrkishi/svelte.d.ts
Last active November 19, 2018 00:04
Show Gist options
  • Save Crisfole/99cecb549e08c2e28ff5f41b11d62d7e to your computer and use it in GitHub Desktop.
Save Crisfole/99cecb549e08c2e28ff5f41b11d62d7e to your computer and use it in GitHub Desktop.
Type definitions for Svelte components
// When importing an html file, assume it's a svelte component
declare module '*.html' {
type State = Record<string, any>;
type Changed = Record<string, boolean>;
type ChangeArgs = {
changed: Changed,
current: State,
previous: State
};
interface Cancellable {
cancel: () => void
};
export default class Component {
root: Component;
options: State;
constructor(init: { target: Element, data?: State });
set(data: State) : void;
get(): State;
on(event: string, callback: (event: any) => void): Cancellable;
on(event: 'state', callback: (changeArgs: ChangeArgs) => void): Cancellable;
on(event: 'update', callback: (changeArgs: ChangeArgs) => void): Cancellable;
on(event: 'destroy', callback: () => void): Cancellable;
fire(event: string, data: any) : void;
destroy() : void;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment