Skip to content

[TypeScript] Action Type #6538

@NickClark

Description

@NickClark

Describe the bug

An action type should be available to developers. One is available if you stay within a *.svelte file, but isn't present outside of it.

Reproduction

Define an action in your svelte file:

function onResize(
  node: HTMLDivElement,
  callback: (entry: DOMRectReadOnly) => void,
): SvelteActionReturnType {
  // ...
}

and the types work.

Move the action outside to its own module, and you no longer have any types you can import to ensure action type.

Maybe something like this would work:

type SvelteActionReturnType<P> = {
  update?: (newParams: P) => void;
  destroy?: () => void;
} | void;

type SvelteActionType<P> = (
  node: Element,
  params: P,
) => SvelteActionReturnType<P>

Logs

No response

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 14.89 GB / 24.99 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.2.0 - ~/.asdf/installs/nodejs/16.2.0/bin/node
    npm: 7.13.0 - ~/.asdf/installs/nodejs/16.2.0/bin/npm
  npmPackages:
    svelte: ^3.38.2 => 3.38.2
    vite: ^2.3.7 => 2.3.7

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    runtimeChanges relating to runtime APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions