Jss Typescript cannot accept value of array
See original GitHub issuehi, after i upgrading jss to v 10.6.0, my code break!
It seem the typescript definition is wrong. See the TS code below:
const otherStyle1: JssStyle = {
background: 'red',
opacity: 5,
};
const otherStyle2: JssStyle = {
background: 'red',
opacity: 5,
};
const test = createUseStyles({
main: {
extend: otherStyle1 // FINE, otherStyle1 is acceptable JssValue
},
});
const test2 = createUseStyles({
main: {
extend: [otherStyle1, otherStyle2] // <== TYPESCRIPT ERROR HERE
},
});
It seem the prop value only accept string, number, another style, but not an array
<prop name: string> : <prop value: (string | number | function)>
in jss however, the extend
is a special prop name. We should either passing a single value or an array of value,
so the TS definition should be:
<prop name: string> : <prop value: (string | number | function | (string | number | function)[])>
to temporary workaround the problem, I just force the prop value as non array:
const test2 = createUseStyles({
main: {
extend: [otherStyle1, otherStyle2] as JssStyle
},
});
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Reactjs/Typescript cannot pass array of items as property to ...
I have a several classes in a project, created with create-react-app, and I want to pass an array of objects down to child...
Read more >Array.prototype.at() - JavaScript - MDN Web Docs
Array.prototype.at(). The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers.
Read more >JavaScript Let - W3Schools
Variables defined with let cannot be Redeclared. Variables defined with let must be ... Variables declared with the var keyword can NOT have...
Read more >Immutable.js
Designed to inter-operate with your existing JavaScript, Immutable.js accepts plain JavaScript Arrays and Objects anywhere a method expects a Collection .
Read more >Data Structures: Objects and Arrays - Eloquent JavaScript
Objects allow us to group values—including other objects—to build more ... Because you can't use the dot notation with numbers and usually want...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
here I reproduce the error: https://codesandbox.io/s/flamboyant-vaughan-mk079?file=/src/App.tsx
the error: Type ‘JssStyle<any, undefined>[]’ is not assignable to type 'false | (string & {}) | (number & {}) | (string | number | (string | number)[])[] | Observable<false | (string & {}) | { alignContent?: (string & {}) | …
the extend is a special prop than other props. It should accept a single value or multiple values (an array).