Open brainkim opened 3 years ago
@brainkim I'm one of the authors that landed non-react custom jsxFactory compiler option. I'm not sure what effort it would take to get ""
, but null totally works and has a test case in the repo.,
you can do jsxFragmentFactory: "null"
, and use that in your custom createElement to decide between a fragment and an actual tag.
It's used by snabbdom-jsx-lite https://github.com/nojvek/snabbdom-jsx-lite/blob/master/tsconfig.json#L8
@nojvek Ah I should have figured that null
would have been supported; I just assumed it would be generalized to any literal value, and went ahead and made the Fragment tag the empty string.
The relevant PR is pretty informative about how this works, I’ll try to look through it soon.
Search Terms
JSX factory expression identifier string JSXFragmentFactory
Related Issues
https://github.com/Microsoft/TypeScript/issues/20469 https://github.com/microsoft/TypeScript/pull/38720
Suggestion
Allow non-identifiers to be used as the JSXFragmentFactory. Currently, attempting to use a non-identifier like the empty string results in the following error:
My config:
Use Cases
My JSX framework defines the
Fragment
tag as the empty string. Babel’s JSX support allows non-identifiers to be used as the JSXFragmentFactory so I wonder why we can’t do the same in TypeScript.Using an identifier is a little more awkward.
Examples
With the
jsxFactory
set tocreateElement
and thejsxFragmentFactory
set to the empty string, emitted code might look like the following.Checklist
My suggestion meets these guidelines: