Skip to content
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

add support of TS Optional variance annotations #2102

Merged
merged 8 commits into from Apr 3, 2022

Conversation

magic-akari
Copy link
Contributor

This PR add support of TS Optional variance annotations

@magic-akari magic-akari marked this pull request as ready for review March 30, 2022 02:56
expectPrintedTSX(t, "<in T extends={true}></in>", "/* @__PURE__ */ React.createElement(\"in\", {\n T: true,\n extends: true\n});\n")
expectPrintedTSX(t, "<out T extends={true}></out>", "/* @__PURE__ */ React.createElement(\"out\", {\n T: true,\n extends: true\n});\n")
expectPrintedTSX(t, "<in out T extends={true}></in>", "/* @__PURE__ */ React.createElement(\"in\", {\n out: true,\n T: true,\n extends: true\n});\n")
expectPrintedTSX(t, "<in T,>() => {}", "() => {\n};\n")
Copy link
Owner

@evanw evanw Apr 1, 2022

Choose a reason for hiding this comment

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

Where did these test cases come from? I can't reproduce this. The latest nightly build of the TypeScript compiler gives this for <in T,>() => {} instead when JSX is enabled:

React.createElement("in", { T: true }, "() => ");

and this when JSX is disabled:

T,  > ();
{ }

Edit: The reason why I'm now moving forward with testing this PR against the nightly TypeScript compiler is that the TypeScript PR for this has landed and support for the in/out modifiers now appears to work in nightly builds. For example, this code now works fine in nightly builds:

type Foo<out T> = () => T

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks.
I will report this issue to TypeScript repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right.
It's TypeScript Error TS1273.

I have modified the code and added some more test cases.

- increase test coverage
- fix bug: anonymous classes don't support in/out
- better error messages when in/out isn't allowed
- more robust parsing of invalid in/out sequences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants