question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jss Typescript cannot accept value of array

See original GitHub issue

hi, 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
heyymarcocommented, Mar 30, 2021

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 & {}) | …

0reactions
heyymarcocommented, Mar 30, 2021

the extend is a special prop than other props. It should accept a single value or multiple values (an array).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found