Replies: 11 comments 8 replies
-
Then we could just allow multiple Also, we have similar mechanisms for The only improvement that I would like is to directly expose the interfaces in order to ease their extension. |
Beta Was this translation helpful? Give feedback.
-
Another solution is to change the proposed syntax: <input use={[someDirective, args]} /> To accept multiple directives: <input use={[[directiveOne, args], [directiveTwo, args]]} />
// or array of object syntax
<input use={[{
directive: directiveOne,
args: [arg1, arg2]
}, {
directive: directiveTwo,
args: [arg1, arg2]
}]}
/> Benefits:
Drawbacks:
|
Beta Was this translation helpful? Give feedback.
-
I think the required type definitions are mostly a non-issues, since the main point of directives is reusability, a pattern most likely employed by libraries, so it makes sense to keep the definitions of types and functions in the same file. The problem that typescript's over-eager tree shaking eats the import is one that should be fixed, though. However, I'm a firm believer in fixing bugs where they arise, so we should try to help fix typescript instead of making Solid worse in order to work around it. |
Beta Was this translation helpful? Give feedback.
-
The title of this discussion should be changed to
Directives in typescript are defacto not working, the workarounds lead to other bugs, and discussions and reports are all over this repository. Let's aggregate the all discussion in this discussion. |
Beta Was this translation helpful? Give feedback.
-
How about the following syntax? Directives expose the element ref and iterate over an array of functions that take the element ref as the first argument. Anonymous functions can be used to pass additional arguments. // single directive
<div directives={[clickOutside]}></div>
// single directive with arguments
<div directives={(element) => [clickOutside(element, args)]}</div>
// multiple directives
<div directives={[clickOutside, someOtherDirective]}> Pros
Cons
|
Beta Was this translation helpful? Give feedback.
-
tl;dr: Just read the last few lines of this comment 😉 I've not seriously worked with solid, yet. Just a bit noodling around with Solid Playground. So please let me share a kinda Solid beginner experience when meeting I start reading the Solid tutorial. The first issue I meet is the follwowing: Okay, I think: The IDE is just not smart enough for Solid. Then I try to modify this Okay, as a TypeScript user, I know that you may have to extend an interface somewhere (I guess, that was meant in the following sentence somewhere above: Looks promising ... another search on Github leads to the following lines: solid/packages/solid/web/test/element.spec.tsx Lines 8 to 14 in a209b35 ... looks even more promising, now. Okay, I give it a try: declare module "solid-js/jsx-runtime" {
namespace JSX {
interface Directives {
clickOutside: any; // `any` should finally be replaced with the proper type, of course
}
}
} Seems to work ... fine! To resume, issues and challenges are:
I friendly disagree with the following comment
What's wrong with @elite174's propsal? Is all that strange Btw, I personally would consider to use Then you could use something like <input ref={someDirective(a, b, c)} />
<input ref={[directiveOne(x), directiveTwo(y, z)]} /> |
Beta Was this translation helpful? Give feedback.
-
Typescript 5 added |
Beta Was this translation helpful? Give feedback.
-
I was thinking on how tanstack/router solved a related (?) problem with typesafe links, with the elegant solution that you import Maybe something like this could work for registering directives for your app? // app.ts
import {extendBaseElements} from "solid/something"
const app = extendBaseElements({
directiveA: () => ...,
directiveB: () => ....
})
export default app // button.tsx
import {button}from './app.ts'
const myButton = () => <button use:directiveA={} use:directiveB={} /> If the lowercase jsx elements cant be changed, it could return uppercase |
Beta Was this translation helpful? Give feedback.
-
I write a plugin that auto inject directives at compile time, which maybe useful https://github.com/subframe7536/unplugin-solid-directive but I quite agree that |
Beta Was this translation helpful? Give feedback.
-
I started working with solid last week, and had a great time using it, till the time i ran into the exact same issue and i landed on this thread. Yes honestly the once again Love the library using it for a week and i kept on thinking why i was using react all this time |
Beta Was this translation helpful? Give feedback.
-
Adding to this discussion... I agree it feels a bit hacky. I have this autofix with VSCode on my codebases and it removes the import because the LSP thinks it's not being used, but SolidJS does. "editor.codeActionsOnSave": {
"source.organizeImports": "always"
}, |
Beta Was this translation helpful? Give feedback.
-
Looks like current implementation of directives is a bit "hacky": a developer needs to add extra stuff to babel-config and deal with global types.
Is it possible to change the current syntax?
Now it looks like this:
<input use:someDirective={[args]} />
Instead it could be something like this:
<input use={[someDirective, args]}
/>In this case it's possible to add extra field to the
CustomAttributes<T>
interface.So this implementation implies that JSX elements can have multiple
use
attributes. In this case no changes to babel-config needed.WDYT?
Beta Was this translation helpful? Give feedback.
All reactions