From 7071449ac20afae2c2126113680a2f7d1ae3145f Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Sun, 6 Aug 2023 12:20:41 -0400 Subject: [PATCH] Document DirectiveFunctions --- langs/en/guides/typescript.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/langs/en/guides/typescript.md b/langs/en/guides/typescript.md index a8660ba4..487d63a1 100644 --- a/langs/en/guides/typescript.md +++ b/langs/en/guides/typescript.md @@ -575,7 +575,7 @@ declare module "solid-js" { If you define custom directives for Solid's [`use:___` attributes](https://www.solidjs.com/docs/latest/api#use%3A___), -you can type them in the `Directives` interface, like so: +you can type them by extending the `DirectiveFunctions` interface, like so: ```tsx function model(element: HTMLInputElement, value: Accessor>) { @@ -586,8 +586,8 @@ function model(element: HTMLInputElement, value: Accessor>) { declare module "solid-js" { namespace JSX { - interface Directives { // use:model - model: Signal; + interface DirectiveFunctions { // use:model + model: typeof model; } } } @@ -597,6 +597,19 @@ let [name, setName] = createSignal(''); ; ``` +If you just want to constrain the second argument to the directive function, +you can extend the older `Directives` interface: + +```tsx +declare module "solid-js" { + namespace JSX { + interface Directives { // use:model + model: Signal; + } + } +} +``` + If you're `import`ing a directive `d` from another module, and `d` is used only as a directive `use:d`, then TypeScript (or more precisely, [`babel-preset-typescript`](https://babeljs.io/docs/en/babel-preset-typescript))