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.

TypeScript error on <style> with attributes `global` and `jsx`

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #137-Ubuntu SMP Wed Jun 15 13:33:07 UTC 2022
Binaries:
  Node: 16.14.2
  npm: 8.7.0
  Yarn: 1.22.5
  pnpm: N/A
Relevant packages:
  next: 12.2.1-canary.2
  eslint-config-next: N/A
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

In my project when I try to create a component with global style I get a TypeScript error:

// Test.tsx

export function Test() {
  return (
    <div>
      <style global jsx>{``}</style>
      {/*    ~~~~~~    */}
    </div>
  )
}
Type '{ children: string; global: true; jsx: true; }' is not assignable to type 'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.
  Property 'global' does not exist on type 'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.ts(2322)

And what seems strange is that styled-jsx@5.0.2 seems to correctly define extension of react type with:

declare module 'react' {
  interface StyleHTMLAttributes<T> extends HTMLAttributes<T> {
    jsx?: boolean
    global?: boolean
  }
}

But for some reason, this seems not to be used by TypeScript.

Expected Behavior

No TS error.

Link to reproduction

https://codesandbox.io/s/musing-mcnulty-i2crqc?file=/components/Test.tsx

To Reproduce

Just hover the global attribute in order to see the TypeScript error.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
tangye1234commented, Jul 7, 2022

file: ./node_modules/next/index.d.ts

image

If I changed the selected line into

/// <reference path="./dist/styled-jsx-types/global.d.ts" />

then all problems are addressed.

5reactions
Chamberlainfranciscommented, Sep 6, 2022

This issue still exists with v12.2.5 although I am not using typescript, I still got this error during build Unknown property 'jsx' found on here <style jsx>{ }</style>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled-jsx typescript error after migrating to monorepo ...
According to this closed issue in vercel, I should be able to fix this by simply running yarn add -D @types/styled-jsx , but...
Read more >
TypeScript: Documentation - JSX
As of TypeScript 2.8, if JSX. ElementAttributesProperty is not provided, the type of first parameter of the class element's constructor or Function Component's ......
Read more >
TypeScript and React: Styles and CSS - fettblog.eu
Styled JSX​​ js framework. It goes its own route of providing scoped styles in style properties, without changing anything to original components.
Read more >
Global attributes - HTML: HyperText Markup Language | MDN
Chrome Edge accesskey Full support. ChromeYes. Toggle history Full support. Edge12. Tog... autocapitalize Full support. Chrome43. Toggle history Full support. Edge79. Tog... autocomplete Full support. ChromeYes....
Read more >
Fragments
In the future, we may add support for additional attributes, such as event handlers. Live Demo. You can try out the new JSX...
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