-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance typing in vanjs-core and vanjs-jsx #143
Conversation
Thanks so much for your PR! A few initial take aways:
|
Of course, take your time @Tao-VanJS , the changes in the PR are relatively small scale changing only two files but they can change a lot of the typing support for VanJS. I don't seem to understand what you mean by The issue with the Let me know if there are any code inconsistencies you would like me to take notice of, and you are probably right about separating the two commits, will stash one of them and make a new PR soon. Note: The |
First, about code style changes introduced by this PR. For instance, I've noticed the changes like that: I understand the code style changes might be introduced by some auto-formatting tools. But the code style of VanJS is currently maintained manually. Using auto-formatting tools will introduce lots of code style changes that make the real changes of this PR hard to see. It will also introduce inconsistent coding styles across different files. Second, about the type system changes in this PR, I cloned your fork. And I found lots of typing errors just in the test file. I guess there will probably be a long way to go if we ever want this PR doesn't break any existing code. Specifically, regarding to the comments about <span data-index="1"></span> In the current version of VanJS, it's very easy to build it with the code: span({"data-index": 1}) But I guess there will be type errors if the current PR is applied. Last but not least, in the current version of |
What I understand is that -excluding the code style, which was caused by prettier and possibly by my usual coding style in the rest of my projects- the issues are mostly because the typing is too strict, types like |
I think in React, it also supports specifying arbitrary attributes in Regarding to how to proceed with the improvement ideas brought up by this PR, I am suggesting to break down the problem into pieces and tackle them piece by piece:
I am planning a new release of VanJS soon with a couple minor improvements in my mind. I am considering to include things that are easy to implement from the list above in the upcoming release. Please let me know if the proposal looks good to you. |
Some updates:
This is already committed to the
I tried to implement this, but it didn't seem to work as I hoped. Specifically, I tried to change the type definition of export type PropValue<K> = K extends `on${infer _}` ?
Primitive | ((e: any) => void) | null :
Primitive | null
export type Props = {
[K in string]: PropValue<K> | StateView<PropValue<K>> | (() => PropValue<K>)
} But
Support for auto-completion also seems hard to add. Think about a regular workflow, where a user typically writes: div(
{
id: "some-id",
class: "some-class",
},
<children>,
) When the user specify the In summary, there probably isn't too much we can do in the short term other than using |
Agree 👍, will try to make smaller changes in the future, but I'm happy nonetheless to give new insight. And about typing in React, I was talking about the HTML JSX elements rather than functional components, in React, an element like a div or an input will provide auto-completion for its props, and will trigger a typescript error when a non-existing attribute is added as long as it doesn't start with |
@all-contributors please add @yahia-berashish for ideas |
I've put up a pull request to add @yahia-berashish! 🎉 |
FYI, in VanJS |
Great, will continue to work on #142 to fix type issues in VanJSX. |
This PR fixes #142
It modifies the Tags and Props in the core.
And uses the modified types in VanJSX.