Title: Props requiring casting on complex type (and defaultProps not settable) · Issue #28614 · microsoft/TypeScript · GitHub
Open Graph Title: Props requiring casting on complex type (and defaultProps not settable) · Issue #28614 · microsoft/TypeScript
X Title: Props requiring casting on complex type (and defaultProps not settable) · Issue #28614 · microsoft/TypeScript
Description: Search Terms: defaultProps React.RefForwardingComponent ExoticComponent Code // import { cx } from "emotion"; import * as React from "react"; // import modifiers, { ModifierProps } from "../../modifiers"; interface RenderAsExoticComponen...
Open Graph Description: Search Terms: defaultProps React.RefForwardingComponent ExoticComponent Code // import { cx } from "emotion"; import * as React from "react"; // import modifiers, { ModifierProps } from "../../modi...
X Description: Search Terms: defaultProps React.RefForwardingComponent ExoticComponent Code // import { cx } from "emotion"; import * as React from "react"; // import modifiers, { ModifierProp...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28614
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Props requiring casting on complex type (and defaultProps not settable)","articleBody":"**Search Terms:**\r\ndefaultProps React.RefForwardingComponent ExoticComponent\r\n\r\n**Code**\r\n```typescript\r\n// import { cx } from \"emotion\";\r\nimport * as React from \"react\";\r\n\r\n// import modifiers, { ModifierProps } from \"../../modifiers\";\r\n\r\ninterface RenderAsExoticComponent\u003c\r\n TOwnProps,\r\n TDefaultComponent extends\r\n | keyof JSX.IntrinsicElements\r\n | React.ComponentType\u003cany>\r\n>\r\n extends Pick\u003c\r\n React.ForwardRefExoticComponent\u003cany>,\r\n keyof React.ForwardRefExoticComponent\u003cany>\r\n > {\r\n (\r\n props: React.ComponentPropsWithRef\u003cTDefaultComponent> &\r\n TOwnProps & { renderAs?: never },\r\n ): JSX.Element | null;\r\n \u003cTAsComponent extends keyof JSX.IntrinsicElements | React.ComponentType\u003cany>>(\r\n props: React.ComponentPropsWithRef\u003cTAsComponent> &\r\n TOwnProps & { renderAs: TAsComponent },\r\n ): JSX.Element | null;\r\n}\r\n\r\nfunction renderAsComponent\u003c\r\n TOwnProps,\r\n TDefaultElement extends React.ComponentType\u003cany> | keyof JSX.IntrinsicElements\r\n>(\r\n factory: React.RefForwardingComponent\u003c\r\n any,\r\n TOwnProps & {\r\n renderAs?: React.ComponentType\u003cany> | keyof JSX.IntrinsicElements;\r\n className?: string;\r\n }\r\n >,\r\n defaultElement: TDefaultElement,\r\n) {\r\n const forward = React.forwardRef(factory);\r\n forward.defaultProps = { renderAs: defaultElement };\r\n // todo: apparently a bug, use workaround\r\n // forward.defaultProps = {};\r\n // forward.defaultProps.renderAs = defaultElement;\r\n return forward as RenderAsExoticComponent\u003cTOwnProps, TDefaultElement>;\r\n}\r\n\r\ninterface ModifierProps {\r\n textColor?: \"white\" | \"black\";\r\n pull?: \"left\" | \"right\";\r\n}\r\n\r\nconst Element = renderAsComponent\u003cModifierProps, \"div\">(\r\n ({ className, renderAs, ...allProps }, ref) => {\r\n const props = {\r\n // className: cx(className, modifiers.classNames(allProps)) || undefined,\r\n ref,\r\n // ...modifiers.clean(allProps),\r\n };\r\n return React.createElement(renderAs!, props);\r\n },\r\n \"div\",\r\n);\r\n\r\nexport default Element;\r\n```\r\n\r\n```ts\r\nexport const Example: React.SFC\u003c{}> = () => (\r\n \u003cElement textColor=\"white\" pull={\"left\" as \"left\"}>\r\n Child\r\n \u003c/Element>\r\n);\r\n```\r\n\r\n**Expected behavior:**\r\n1) `defaultProps` can be set directly\r\n2) `props` work without casting\r\n\r\n**Actual behavior:**\r\n1) `defaultProps` cannot be set directly (see workaround in code)\r\n2) `props` do not work without being cast.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\nNo.","author":{"url":"https://github.com/dfee","@type":"Person","name":"dfee"},"datePublished":"2018-11-20T07:30:56Z","url":"https://github.com/microsoft/TypeScript/issues/28614"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b174622-ee12-c016-45a3-327988b9c93e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C422:3F8AB1:2A55534:35C7A54:6B018F7A |
| html-safe-nonce | b6467401f496a50d260064a13c119c8654c913ec6d1259020dc5dad19fb9ebf1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDIyOjNGOEFCMToyQTU1NTM0OjM1QzdBNTQ6NkIwMThGN0EiLCJ2aXNpdG9yX2lkIjoiNjY5MTE4MDgwODM3MzM3NDg0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 148ebe72135f8f4f0af5a0999a9eb984f33cbef87d9cc1e4b634ccb0ad310dcb |
| hovercard-subject-tag | issue:382534540 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/28614/issue_layout |
| twitter:image | https://opengraph.githubassets.com/965ab0db42bdba99ce822707bfd3604ad0469253d011975ee7327dc546349489/microsoft/TypeScript/issues/28614 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/965ab0db42bdba99ce822707bfd3604ad0469253d011975ee7327dc546349489/microsoft/TypeScript/issues/28614 |
| og:image:alt | Search Terms: defaultProps React.RefForwardingComponent ExoticComponent Code // import { cx } from "emotion"; import * as React from "react"; // import modifiers, { ModifierProps } from "../../modi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dfee |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width