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.

TS: Property 'sx' does not exist on type 'SVGProps<SVGRectElement>'

See original GitHub issue

Describe the bug

I get a TypeScript error when I try to use the sx prop on an SVG element claiming that Property 'sx' does not exist on type 'SVGProps<SVGRectElement>', yet it works just fine anyway.

To Reproduce

/** @jsx jsx */

import React from 'react';
import { jsx } from 'theme-ui';

const Foo = () => <rect sx={{ fill: 'papayawhip' }} />

Expected behavior I expect sx to be a valid prop on SVG elements or for sx to fail on SVG elements. (Would much rather the former since it works anyway 🙂.)

Screenshots N/A

Additional context N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hasparuscommented, Jun 19, 2020

Here’s a CodeSandbox demo https://codesandbox.io/s/theme-ui-rect-fg6g0.

Theme UI 0.3.1 is written fully in JavaScript. You can notice that types appear on hover in the demo, because @types/theme-ui is installed automatically by the IDE.

When you’re using TypeScript, you need to install @types libs yourself.

Does installing @types/theme-ui solve the problem? If not, I’d like to help figure it out.

0reactions
hasparuscommented, Jun 22, 2020

Okay, this is a bit weird. I doublechecked in DefinitelyTyped, and the way both versions register sx prop is exactly the same.

I just installed 0.4.0-rc.1 and the problem seems to have gone away.

There are still some rough edges regarding TypeScript in 0.4.0-rc.1. Feel free to ping me here if you encounter any problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to declare types of props of SVG component? [React ...
I've been facing this problem, and this solution worked fine for me: declare module "*.svg" { import { ReactElement, SVGProps } from "react" ......
Read more >
The `sx` Prop - Theme UI
The sx Prop. The sx prop lets you style elements inline, using values from your theme. To use the sx prop, add the...
Read more >
Troubleshooting - Material UI - MUI
[Types] Property "palette", "spacing" does not exist on type 'DefaultTheme'. This error arises because makeStyles is now exported from the @mui/styles package, ...
Read more >
<rect> - SVG: Scalable Vector Graphics - MDN Web Docs
The <rect> element is a basic SVG shape that draws rectangles, defined by their position, width, and height. The rectangles may have their...
Read more >
Why I am getting typescript error when trying to use Material-ui ...
Property 'alt' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Avatar> & Readonly<AvatarProps> & Readonly<{ children ...
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