-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
types: support xastscript used as JSX in typescript #7
Conversation
/** @jsx x */ | ||
import x = require('xastscript') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two notes:
- 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
- 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.
There was a problem hiding this comment.
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.
Co-authored-by: Remco Haszing <[email protected]>
8696942
to
2466654
Compare
There was a problem hiding this 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 😅
/** @jsx x */ | ||
import x = require('xastscript') |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
closing in favor of #3 |
Follow up to #3, I'd be okay with either PR moving forward, but wanted to avoid committing over @remcohaszing's work.