Jss: createUseStyles typescript declaration missing

Created on 14 Jun 2019  路  9Comments  路  Source: cssinjs/jss

__Steps to reproduce:__

  1. Create a fresh react app

    • npx create-react-app use-styles-ts

    • cd use-styles-ts

  2. Add react-jss and typescript

    • yarn add react-jss@next typescript

    • yarn add -D @types/react

  3. Rename App.js -> App.tsx and implement a simple usage of createUseStyles hook
import React from 'react';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  App: { textAlign: 'center' },
})

function App() {
  const classes = useStyles();
  return (
    <div className={classes.App}>
    ...
  1. Start app

    • yarn start

__Expected behavior:__

  • App compiles and runs normally

__Describe the bug:__

  • App fails to compile with error:
Failed to compile.

/Users/robcmills/src/jss-use-styles/src/App.tsx
TypeScript error in /Users/robcmills/src/jss-use-styles/src/App.tsx(2,10):
Module '"../../../../../Users/robcmills/src/jss-use-styles/node_modules/react-jss/src"' has no exported member 'createUseStyles'.  TS2305

    1 | import React from 'react';
  > 2 | import { createUseStyles } from 'react-jss';
      |          ^
    3 | import logo from './logo.svg';
    4 | import './App.css';
  • Apparently a typescript declaration for createUseStyles is missing from react-jss/src/index.d.ts
  • I have confirmed that adding a declaration for createUseStyles to this file silences the error

__Versions:__

  • react-jss: 10.0.0-alpha.17
  • typescript: 3.5.2
  • Browser [e.g. chrome, safari]: Chrome Version 74.0.3729.131 (Official Build) (64-bit)
  • OS [e.g. Windows, macOS]: macOS Sierra version 10.12.6
enhancement typescript

Most helpful comment

Having the same issue, just wondering why the issue has been closed.

All 9 comments

@kof

Looks like this is already accomplished in @HenriBeck 's udpate-ts-typings branch:
https://github.com/cssinjs/jss/commit/a9881d9f34b50bf366faef0787ddff2a2644bdee

Just needs to be PR'd and merged?

I started already with the typings. I will finish them today

I want to do some more testing tomorrow, and then we will release a new version.

Sorry, had a few busy weeks with work and university. Finally got to check the typing and they look good.

I also started on adding proper type completion for the style object, but it's not correctly inferred at the moment.

@HenriBeck Hi there! May I wonder why this was closed? The types seem to still be missing, for _createUseStyles_ anyways.
I guess, it is not entirely relevant, since I've found out there is a v.10 release of react-jss and documentation I was reffering to was issued for this new version, which is not part of npm package(v8.6.1).
Could you clarify what's the state of new version and if there are any working typescript examples for current version 8.6.1?

Having the same issue, just wondering why the issue has been closed.

@Dar0n there should be @types/react-jss version which is for v8 of react-jss.

@Kudze can you provide an example then maybe? It works for me. You also need to be on the latest v10 alpha for it to work.

Any update on this?

@stewartduffy I know this is now closed but I am having a similar issue: https://github.com/cssinjs/jss/issues/1344

React, using Material-UI via @material-ui/core/styles I'm getting all kinds of type errors when trying to define styles.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergiop picture sergiop  路  5Comments

brianmhunt picture brianmhunt  路  5Comments

brianmhunt picture brianmhunt  路  5Comments

antoinerousseau picture antoinerousseau  路  3Comments

janhartmann picture janhartmann  路  5Comments