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.

Remove irrelevant types from JSX namespace

See original GitHub issue

The JSX namespace in TypeScript has a special meaning. There’s a specific set of types that can be defined in a JSX namespace to make JSX behave in a certain way. This is (partially) documented here.

The following properties have a special meaning:

  • Element
  • ElementClass
  • ElementAttributesProperty
  • ElementChildrenAttribute
  • IntrinsicAttributes
  • IntrinsicElements
  • LibraryManagedAttributes

However, in the Preact typings the following types are also defined on the JSX namespace:

  • SVGAttributes
  • PathAttributes
  • DOMAttributes
  • HTMLAttributes

Events and event handlers

  • TargetedEvent
  • TargetedAnimationEvent
  • TargetedClipboardEvent
  • TargetedCompositionEvent
  • TargetedDragEvent
  • TargetedFocusEvent
  • TargetedKeyboardEvent
  • TargetedMouseEvent
  • TargetedPointerEvent
  • TargetedTouchEvent
  • TargetedTransitionEvent
  • TargetedUIEvent
  • TargetedWheelEvent
  • EventHandler
  • AnimationEventHandler
  • ClipboardEventHandler
  • CompositionEventHandler
  • DragEventHandler
  • FocusEventHandler
  • GenericEventHandler
  • KeyboardEventHandler
  • MouseEventHandler
  • PointerEventHandler
  • TouchEventHandler
  • TransitionEventHandler
  • UIEventHandler
  • WheelEventHandler

The JSX namespace in Preact is called JSXInternal. This makes it unclear if these types are supposed to be consumed or not.

Since these types are useful, especially the event handlers, I propose to move all these types to the preact namespace instead. The JSXInternal namespace can import these types an expose type aliases using the @deprecated annotation. They can be removed in the next major release.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
marvinhagemeistercommented, Aug 20, 2020

FYI: We consciously moved away from the global JSX type so that we can co-exist with other JSX typings being present. This should remain. See the last section of the TypeScript docs on this page for more information: https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions

1reaction
remcohaszingcommented, Aug 20, 2020

I learnt some things about TypeScript and JSX while writing mini-jsx.

I noticed in props.js a similar way is used to assign props to DOM nodes. This means the existing builtin TypeScript types from HTMLElementTagNameMap and SVGElementTagNameMap could be used to avoid the need to maintain most of the current HTMLAttributes interface in Preact.

This will also improve typings, i.e. an input has a checked property in the TypeScript DOM types, but not a div element. In Preact there’s currently no distinction.

Instead of introducing the deprecation policy I described in the original comment, I’d prefer to take the liberty to make some breaking changes.

Is there an ETA for Preact 11? I think it’s better to make these changes for a major release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove irrelevant types from JSX namespace - Bountysource
Since these types are useful, especially the event handlers, I propose to move all these types to the preact namespace instead. The JSXInternal...
Read more >
Clean up your React component types | by José Pereira | xgeeks
Complicates the types of Components with a Namespace. Cleaner component types make your code more future-proof and decoupled.
Read more >
JSX In Depth - React
Specifying The React Element Type. The first part of a JSX tag determines the type of the React element. Capitalized types indicate that...
Read more >
'React' was used before it was defined - Stack Overflow
Actually I tried to delete .eslintrc.js at all, but had the same error. reactjs · typescript · create-react-app · eslint.
Read more >
Documentation - JSX - TypeScript
Using JSX with TypeScript. ... TypeScript supports embedding, type checking, and compiling JSX directly to JavaScript. ... declare namespace JSX {.
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