Emotion: Can't find declaration files after switch to macro

Created on 15 Oct 2018  路  10Comments  路  Source: emotion-js/emotion

  • emotion version: 9.2.12
  • react version: 16.5.2

Relevant code.

import styled from 'react-emotion/macro'

const H1 = styled.h1({
  fontSize: 48,
  textAlign: 'center',
})

What you did:

Using react-emotion/macro in create-react-app.

What happened:

Visual Studio Code can't find typescript declaration file and autocompletion stops working.

TypeScript

Most helpful comment

Updated workaround:

declare module '@emotion/styled/macro' {
  import styled from '@emotion/styled';
  export * from '@emotion/styled';
  export default styled;
}

All 10 comments

Thank you for reporting this issue!
We currently don't have typings for macro files.
I will add types for those files in emotion@10, after fixing some other issues.

Thanks for your effort.

@irrigator In a meantime, you can define your local definition like

declare module 'react-emotion/macro' {
  import styled from 'react-emotion';
  export * from 'react-emotion';
  export default styled;
}

hi, any update here? I'm using emotion v10 and I'm getting the same error

Could not find a declaration file for module '@emotion/css/macro'
Could not find a declaration file for module '@emotion/css/macro'

am I missing something?

thanks

No, it's not yet provided. I'm recently too busy to update one. If you want to send a PR for this, feel free to send it and we will welcome.

Updated workaround:

declare module '@emotion/styled/macro' {
  import styled from '@emotion/styled';
  export * from '@emotion/styled';
  export default styled;
}

It seems this hasn't been published yet - any plans on a release containing this?

Has this been published? I'm still getting the error :/

As of @emotion/styled v10.0.11 (current version), the file added in #1315 (macro.d.ts) is not available as it has not been whitelisted in the package.json. So it does not appear in the current build available on NPM.

It is also curious that v10.0.11 doesn't appear in the GitHub releases panel, only on NPM and inside the CHANGELOG.md for @emotion/styled.

I've created a PR to fix this (#1369).

For future reference, you can browse the latest release here and browse v10.0.11 specifically here.

My PR to ship macro.d.ts has been merged. This issue should be properly resolved with the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kentcdodds picture kentcdodds  路  3Comments

artooras picture artooras  路  3Comments

pimmey picture pimmey  路  3Comments

tkh44 picture tkh44  路  3Comments

mitchellhamilton picture mitchellhamilton  路  3Comments