You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By looking at this code we could expected that the textNode would be blue. When we do the apply the second argument expected an array of arguments (see: apply doc). Here the args variable represents all the argument passed to style the div. It's like if we were doing the folowing:
// to simplify the `this` "assignment" isn't part of the examplecss({color: "blue"},(props)=>({color: props.theme.palette.primary}),()=>({color: "pink"}),// ...);
The issue is that the css method from goober only take one argument. Everything after the first argument is ignored.
/** * css entry * @param {String|Object|Function} val */functioncss(val){
Secondary issue: We could also take the time to improve the types, because currently there's no way to mark the theme prop as not optional an the as prop types should probably be ValidComponent instead of string | number | symbol | undefined
Proposed solution
Only tag function should be allowed to have multiple arguments
There's a way to make the tag function work while restricting regular function call to one argument. Based on what's happening in goober's css function, here's what the types could look like (without the generic type for the props):
importtype{ValidComponent}from"solid-js";typeStylesGenerator=(props: {})=>CSSAttribute|string;typeStylesArg=|string|CSSAttribute|StylesGenerator|Array<CSSAttribute|StylesGenerator>;typeStylesFn=(styles: StylesArg)=>ComponenttypeTagStyleGenerator=(props: {})=>number|string|undefined;typeTagFn=(tag: TemplateStringsArray,
...args: Array<string|TagStyleGenerator>,)=>Component;// This way we can both use a regular function call with// one argument or a tag function with multiple argumentstypeStylingFn=StylesFn&TagFn;
With these types the example at the beginning wouldn't be allowed and the types would fit the implementation.
Let me know what you think.
The text was updated successfully, but these errors were encountered:
Issue
The types allow for multiples arguments when styling a component. The following is correct based on the types.
We could expected that a
textNode
passed toComponent
would bepink
, but with the current implementation the result isblue
(the first argument).It's due to the following lines:
solid-styled-components/src/index.js
Lines 47 to 50 in dec99a0
By looking at this code we could expected that the
textNode
would beblue
. When we do theapply
the second argument expected an array of arguments (see: apply doc). Here theargs
variable represents all the argument passed to style thediv
. It's like if we were doing the folowing:The issue is that the
css
method from goober only take one argument. Everything after the first argument is ignored.https://github.com/cristianbote/goober/blob/b2781bd9d76f5b386e50b5916216430f4532662c/src/css.js#L5-L9
Secondary issue: We could also take the time to improve the types, because currently there's no way to mark the
theme
prop as not optional an theas
prop types should probably beValidComponent
instead ofstring | number | symbol | undefined
Proposed solution
Only tag function should be allowed to have multiple arguments
There's a way to make the tag function work while restricting regular function call to one argument. Based on what's happening in goober's
css
function, here's what the types could look like (without the generic type for the props):With these types the example at the beginning wouldn't be allowed and the types would fit the implementation.
Let me know what you think.
The text was updated successfully, but these errors were encountered: