Jss: Typescript error - Type 'Name' does not satisfy the constraint 'string'

Created on 15 Oct 2019  路  5Comments  路  Source: cssinjs/jss

I'm seeing the following Typescript error:

ERROR in [at-loader] ./node_modules/jss/src/index.d.ts:8:78 TS2344: Type 'Name' does not satisfy the constraint 'string'. Type 'string | number | symbol' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'.

....which I'm circumventing by amending ./node_modules/jss/src/index.d.ts to look like this:

export type Classes<Name extends string = string> = Record<Name, string>

Er, I _think_ that's an issue with jss, but I'm willing to be told otherwise ;)

I'm running typescript v3.6.3, node v10.15.3 and npm v6.11.2 on different OS's.

typescript

Most helpful comment

@bassettb if you are still having this error or anybody else in the future, I found some documentation about the "keyOfStringsOnly" in the tsconfig file. When I removed that setting, it compiled.

All 5 comments

released in 10.0.3

This is still broken in 10.0.3. You can tell from the code in the error message that I have version 10.0.3
```node_modules/jss/src/index.d.ts:18:77 - error TS2344: Type 'Name' does not satisfy the constraint 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.

18 export type Styles = Record
~~~~

node_modules/jss/src/index.d.ts:19:78 - error TS2344: Type 'Name' does not satisfy the constraint 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.

19 export type Classes = Record```

@kof I am seeing the same issue in 10.0.4. I recently upgraded @material-ui to the next major version. In so doing, it upgraded jss to 10.0.4 and now the tsc build fails.

@bassettb if you are still having this error or anybody else in the future, I found some documentation about the "keyOfStringsOnly" in the tsconfig file. When I removed that setting, it compiled.

@sikorsky555 you sir, are an absolute star! I will admit to hacking out Name extends string | number | symbol = string for the best part of two years! Now I can move on with the rest of my life (well, if I wasn't stuck at home on lockdown)! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mg901 picture mg901  路  3Comments

synchronos-t picture synchronos-t  路  4Comments

valZho picture valZho  路  7Comments

EugeneSnihovsky picture EugeneSnihovsky  路  4Comments

trusktr picture trusktr  路  6Comments