styled-components / styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
https://styled-components.com
MIT License
40.11k stars 2.48k forks source link

Cannot infer the 'as' and 'forwardedAs' props by React.ComponentProps #4294

Open XaveScor opened 2 weeks ago

XaveScor commented 2 weeks ago

Environment

typescript: 5.4.5 styled-components: 6.1.8

Reproduction

import * as React from "react";
import styled from "styled-components";

const A = styled.div``;

// Shows a typescript error in v5.4.5
type T1 = React.ComponentProps<typeof A>["as"]
type T2 = React.ComponentProps<typeof A>["forwardedAs"]

// but no error here
<A as='a' />;
<A forwardedAs='a' />;

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcARFDvmQNwBQokscqMAngDZYAmcRJ5Vpx4BaXCUgA7LJJipadOuMms4AQTgBeFuy7cAdN2AA3AAan6dAPRW4AZQAWEAO7pkcdmCypcUYGHgsKGIoOGBJOGMAVn0AFn0ouk8sOAAVAEYtTCoYfQBhCQhpWQAFYjBUAB5kiAJ1AD4AbTI0MgBdJLYvNIAmLOw8XILwIpkYMogK6q6sWobmgmhnZChuHjV5DutbACMAV3hJCDggkLgHIKw6So00TQByZHu4K3r6G74llbXuDYenl5vIA

Steps to reproduce

  1. Open typescript playground

Expected Behavior

as and forwardedAs props are available inside React.ComponentProps type

Actual Behavior

There are no these props