[@types/react] Support data-* attributes on HTMLAttributes
#69864
Unanswered
jsejcksn
asked this question in
Issues with a @types package
Replies: 1 comment
-
|
Thanks for the discussion about "react", some useful links for everyone: Pinging the DT module owners: @johnnyreilly, @bbenezech, @pzavolinsky, @ericanderson, @DovydasNavickas, @theruther4d, @guilhermehubner, @ferdaber, @jrakotoharisoa, @pascaloliv, @Hotell, @franklixuefei, @Jessidhia, @saranshkataria, @lukyth, @eps1lon, @zieka, @dancerphil, @dimitropoulos, @disjukr, @vhfmag, @hellatan, @priyanshurav, @Semigradsky, @mattpocock. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Refer to this Stack Overflow question as motivation for this discussion: Does React's type declarations support the usage of custom data attributes out of the box? — below I'll copy some content from it.
Although custom data attributes (
data-*) are recognized by the TypeScript compiler when using JSX syntax — e.g. this compiles without error…TS Playground
…the React types don't provide element attribute type aliases/interfaces which include them… so correctly typing custom data attributes in a user-defined type becomes the responsibility of the user. Consider the compiler diagnostic error in this example:
TS Playground
In order to allow for custom data attributes in such a user-defined type, they can either be included explicitly at each definition…
TS Playground
…or — they can be defined using the pattern of module augmentation — in a type declaration file in the project at a path that is included in the program's compilation (e.g.
src/types/react_data_attributes.d.ts):Then, at each usage site, the explicit intersection will no longer be needed:
TS Playground
It would be useful for data attributes to be included in this package so that this task is no longer a user burden.
Beta Was this translation helpful? Give feedback.
All reactions