Closed
Description
Describe the problem
Snippets take a single argument. This is for two reasons:
- we initially thought it would be difficult to type variadic snippets
- a vague notion that it might be easier to optimise snippets (e.g. hoisting them) if we know that they always have zero or one arguments
Describe the proposed solution
Hat-tip to @tcc-sejohnson for solving the typing issue:
type Snippet<Args = any, This = any> = Args extends any[] ? (this: This, ...args: Args) => unknown : (this: This, arg: Args) => unknown;
type MyCustomSnippet = Snippet<[firstName: string, lastName: string, dob: Date]>;
type MyCustomSnippetWithOneArg = Snippet<{ firstName: string, lastName: string, dob: Date }>;
I haven't thought deeply about the optimisation question. It may be a non-issue.
Alternatives considered
not doing this
Importance
nice to have
Metadata
Metadata
Assignees
Labels
No labels