-
Notifications
You must be signed in to change notification settings - Fork 85
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
Incorrect attribute typing for van_jsx #142
Comments
@cqh963852, FYI. |
By the way, how to test the VanJS codebase @Tao-VanJS ? |
Here is the development steps for the changes in the core VanJS library: #37. It's not a polished process yet. The external contribution that is complex enough which needs running test to iterate is rare. For small changes, you can just send out the PR for source files and I can take care of the rest (including the testing). |
van/addons/van_jsx/src/jsx-internal.d.ts Lines 27 to 29 in a39557b
There is already a utility type van_jsx is based on van but the interface is not equal to van, so How about the following modification? This can reduce the code length of internal and provide a most basic tag type.
|
But how to handle attributes that are not HTML but handled by Van? const text = van.state("");
<input
// reactive state binding throws a type error since the input element is typed with plain HTML attributes and expects a string
value={text}
oninput={(e) => text.val = e.target.value}
/> The |
Can you post a picture of your error? I'm not sure if you mean
|
What do you say about modifying the |
Did you mean "What are your thoughts on modifying xx" |
I am referring to this comment.
|
There are tens of different element classes in DOM, and each class has tens of properties. Hardcoding the interface of properties for each element class will significantly bloat the size of |
What I was thinking of actually is to use the built-in HTML attributes types, but with modifying the values to include things like states and binding functions @Tao-VanJS The van.d.ts code now looks something like this: ...
export type PropValue<TProp = any> = TProp | StateView<TProp> | (() => TProp);
export type Props<TElement extends Element> = Partial<{
[K in keyof TElement]: PropValue<TElement[K]>;
}>;
export type VanElement<TElement extends Element> = (
first?: Props<TElement> | ChildDom,
...rest: readonly ChildDom[]
) => TElement;
export type Tags = {
[K in keyof HTMLElementTagNameMap]: VanElement<HTMLElementTagNameMap[K]>;
};
// the rest of the file
... These modifications will significantly improve typing in vanjs-core, and synchronize the types with vanjs-jsx. |
This PR should fix the issues, the modifications are pretty small and simple. |
This is another JSX type issue I haven't noticed in the previous issue.
The attributes used for the JSX elements in
jsx-internal.d.ts
are plain HTML attributes, which means that reactive states cannot be used as attributes = no reactive attributes.This can be solved by creating a utility type to modify the attributes, something like this:
I will probably take a look at this issue later if it is still open
The text was updated successfully, but these errors were encountered: