You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I define a type or interface that extends React.HTMLAttributes<HTMLElement>, attempting to cast an array of objects to an array of that type fails if any of those objects has a data- attribute.
🔎 Search Terms
React, JSX, data attributes
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about array type assertions.
Conversion of type '{ label: string; 'data-testid': string; }[]' to type 'MyProps[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type '{ label: string; 'data-testid': string; }' is not comparable to type 'MyProps'.
Object literal may only specify known properties, and ''data-testid'' does not exist in type 'MyProps'.(2352)
🙂 Expected behavior
No type error should occur here.
The text was updated successfully, but these errors were encountered:
Bug Report
When I define a type or interface that extends
React.HTMLAttributes<HTMLElement>
, attempting to cast an array of objects to an array of that type fails if any of those objects has adata-
attribute.🔎 Search Terms
React, JSX, data attributes
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about array type assertions.
⏯ Playground Link
Playground link with relevant code
💻 Code
You can also replicate it more simply with this one-liner:
🙁 Actual behavior
The array fails type checking with this error:
🙂 Expected behavior
No type error should occur here.
The text was updated successfully, but these errors were encountered: