Children of JSX Fragments not recognized as "read." #19939
Labels
Bug
A bug in TypeScript
Domain: JSX/TSX
Relates to the JSX parser and emitter
Fixed
A PR has been merged for this issue
Milestone
Hey folks! I was taking the new JSX fragments syntax for a spin and noticed that there seems to be a glitch when it's used in combination with the
--noUnusedLocals
flag. Looks like TypeScript doesn't recognize declared variables as "read" when they're used within a JSX fragment.One particularly insidious consequence of this bug is that the compiler will strip out imports that it believes are unused---in the sample below, the import for
MyComponent
is removed from the emitted code when it appears within a fragment, but not when it appears between (e.g.)<div />
s.TypeScript Version:
2.7.0-dev.20171110
Code
~ ❯❯❯ tsc --jsx react --noUnusedLocals test.tsx
Expected behavior:
TypeScript should recognize that
MyComponent
,MY_STRING
, andMY_CLASSNAME
are used within the JSX fragment, and not return errors as a consequence of the--noUnusedLocals
compiler flag. Additionally, TypeScript should emit arequire
call for./my-component
.Actual behavior:
The compiler flags
MyComponent
,MY_STRING
, andMY_CLASSNAME
as unused......and strips the
require('./my-component')
line from the emitted JS:The text was updated successfully, but these errors were encountered: