Skip to content

types: support xastscript used as JSX in typescript #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ChristianMurphy
Copy link
Member

@ChristianMurphy ChristianMurphy commented Nov 6, 2020

Follow up to #3, I'd be okay with either PR moving forward, but wanted to avoid committing over @remcohaszing's work.

Comment on lines +1 to +2
/** @jsx x */
import x = require('xastscript')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes:

  1. I opted to create two test files, one for plain ts and another for tsx, to ensure the script can be used independent of jsx
  2. this file does not test fragments, custom fragment syntax /** @jsxFrag null */ is only supported in typescript 4 and above. Out current typings support this usage, however dtslint does not appear to offer a way to run tests in multiple versions of typescript on the same typing file. We would need to have two typings files which would be identical except the header comment.
// TypeScript Version: 3.7

vs

// TypeScript Version: 4.0

and I'd like to avoid splitting the typing just for a header.
Open to other suggestions though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d just drop support for TypeScript < 4. New users will probably already use the latest TypeScript, and users upgrading hastscript are likely to upgrade TypeScript to the latest version in the same change. I know I didn’t encounter any issues when upgrading TypeScript any of my projects.

Copy link
Member

@remcohaszing remcohaszing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to press the submit button. These comments have been pending for a while 😅

Comment on lines +1 to +2
/** @jsx x */
import x = require('xastscript')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d just drop support for TypeScript < 4. New users will probably already use the latest TypeScript, and users upgrading hastscript are likely to upgrade TypeScript to the latest version in the same change. I know I didn’t encounter any issues when upgrading TypeScript any of my projects.

*
* For `xastscript` this defines any string may be used in combination with `xast` `Attributes`.
*/
type IntrinsicElements = Record<string, Attributes>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following tests are is missing:

declare function Bar(props?: Attributes): Element
jsx = <Bar /> // $ExpectError
jsx = <foo>{{}}</foo> // $ExpectError

To fix this, this line should be changed to:

  type IntrinsicElements = Record<string, Attributes & { ''?: Node }>;

This might interfere with support for fragments though.

@ChristianMurphy
Copy link
Member Author

closing in favor of #3

@ChristianMurphy ChristianMurphy deleted the types/support-jsx-in-typescript branch November 23, 2020 21:34
@wooorm wooorm added 👯 no/duplicate Déjà vu and removed ☂️ area/types This affects typings 👶 semver/patch This is a backwards-compatible fix labels Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants