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

Disable JSX:React to prevent syntax conflict with angle-bracket style type assertion in Playground #1968

Closed
wants to merge 1 commit into from

Conversation

LouisSung
Copy link

@LouisSung LouisSung commented Aug 3, 2021

To fix the angle-bracket style type assertion conflict issue microsoft/TypeScript#45308

By a quick review, I found out that there are

  1. default config jsx: monaco.languages.typescript.JsxEmit.None in packages/playground-examples/copy/en/Playground/Config/New Compiler Defaults.ts
  2. and soon be overwritten (?) by JsxEmit.React in packages/sandbox/src/compilerOptions.ts

Please help to check if the 2. is the correct piece of code to be changed _(:3


I make this change mainly to prevent the conflict between the angle-bracket style type assertion and JSX syntax
Here's the quote of my comment in the original issue. If there's any concern on disabling React syntax by default, feel free to have a further discussion : )

Yes, I know the other as style syntax is also available (and I always use it personally); however, some of the sample code (e.g., like the original post) is provided with the angle-bracket style.

Actually, there's a typescript-eslint rule called consistent-type-assertions to limit the syntax of type assertion (also uses assertionStyle: 'as' by default)

However, if I were the designer of the Playground and need to make a trade-off between official TypeScript syntax (<Type>foo) and JSX syntax, I would rather pick the former one as it's part of the standard of TypeScript.


ps, the document also mention this:

  1. Basic Types (old docs):
  2. Everyday Types (new docs ):

Syntax like `<Type>foo` raises error if the flag `JSX: React` is set
Therefore, config the Playground as `JSX: None` by default

Fixes: microsoft/TypeScript#45308
@orta
Copy link
Contributor

orta commented Aug 3, 2021

I'm afraid not, we're keeping JSX as the default as there's likely more people wanting to write JSX code then using the angle brackets - you're welcome to change the JSX option to None in your playgrounds if you'd like that option (or set the compiler option manually if you're using the sandbox in your own code)

@orta orta closed this Aug 3, 2021
@LouisSung
Copy link
Author

LouisSung commented Aug 3, 2021

I can agree with that and thanks for your quick and kind reply : )

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