You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TS files cannot use JSX components declared as a classes in JS/JSX file #14558
This is killing me trying to migrate a large project to Typescript. I've got a hundred plain ol React components and I'd love to be able to do 1 at a time, but once converted to .tsx, they can't import any other .js files without this error.
Reacted by Paul Myburgh, Artem Yarulin, Josh Hornby, kfryauff, Dibyo Majumdar, Leander Melms and Jason Rice
Did you try adding properties to Hello?
It seems like Typescript infers that properties of Hello are of type {}. So you cannot render it from TypeScript as <Hello baz="world"/>.
Here is the compiler output:
error TS2339: Property 'baz' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Hello> & Readonly<{ children?: ReactNode; }> & Readonly<{}>'
It can be worked around with React.createElement:
React.createElement(Hello,{baz: "world"}asany)
or by creating temporary variable with properties but this is quite ugly workaround. Can this be done better?
Can we please reopen it? It doesn't work if component have any props inside and it's a show stopper for React projects which are migrating to TypeScript
Reacted by Andrew Goodale, Alec Merdler, Dibyo Majumdar, Alessandro Mencarini, Kevin Kipp, Andrey Syschikov, Arthur Kay, Yiu, Matej Bransky and Rama Revuri
Mohamed Hegazy (@mhegazy) This makes it very difficult to incrementally adopt TS in a large codebase because we have hundreds/thousands of JS components that will not be converted for the foreseeable future.
so i miss understood the Veniamin Krol (@vkrol)'s comment. I thought he meant getting an error under --noImpclitAny --checkJs which is expected.. but looking at the code again, it is disabled for --noImplcitAny, and that is a bug and should be fixed. apologies for the miss understanding.
Just ran into this as well, just so I'm understanding, with #20232 this fix should work for an incrementally converted codebase when using a non TS React component inside of a TSX component with noImplicitAny enabled
Activity
mhegazy commentedon Mar 9, 2017
Can you give #14396 a try and see if it fixes the issue?
timothyallan commentedon Apr 15, 2017
This is killing me trying to migrate a large project to Typescript. I've got a hundred plain ol React components and I'd love to be able to do 1 at a time, but once converted to .tsx, they can't import any other .js files without this error.
mhegazy commentedon Apr 19, 2017
This is addressed by #14907. Tim (@timothyallan) please give
typescript@2.3a try and let us know if you are running into other issues.robin-anil commentedon May 4, 2017
This is not solved with
typescript@2.3.2I am still seeing issuesmhegazy commentedon May 5, 2017
I see it working on latest. if you are seeing issues please file a new issue:
robin-anil commentedon May 5, 2017
does it work if you rename hello.js to hello.jsx ?
mhegazy commentedon May 5, 2017
gagarski commentedon Jul 11, 2017
Mohamed Hegazy (@mhegazy)
Did you try adding properties to
Hello?It seems like Typescript infers that properties of
Helloare of type{}. So you cannot render it from TypeScript as<Hello baz="world"/>.Here is the compiler output:
It can be worked around with
React.createElement:or by creating temporary variable with properties but this is quite ugly workaround. Can this be done better?
gagarski commentedon Jul 11, 2017
https://github.com/gagarski/tsx-jsx - complete minimalistic example
artemyarulin commentedon Aug 4, 2017
Can we please reopen it? It doesn't work if component have any props inside and it's a show stopper for React projects which are migrating to TypeScript
17 remaining items
vkrol commentedon Nov 22, 2017
Mohamed Hegazy (@mhegazy) this fix does not work if
noImplicitAnycompiler flag is enabled :(mhegazy commentedon Nov 22, 2017
Well.. it is an implicit any... if you want the strict no-
anys-implicitly-added-by-the-compiler, then use `/** Augments */ to specify the type.vkrol commentedon Nov 22, 2017
Mohamed Hegazy (@mhegazy) so in
noImplicitAny-mode/** @augments ... */is the only solution and it will not be changed in the future?gpeal commentedon Nov 22, 2017
Mohamed Hegazy (@mhegazy) This makes it very difficult to incrementally adopt TS in a large codebase because we have hundreds/thousands of JS components that will not be converted for the foreseeable future.
mhegazy commentedon Nov 22, 2017
but it is an implicit
any. you can opt-out of this using--noImplicitAny falsemhegazy commentedon Nov 22, 2017
so i miss understood the Veniamin Krol (@vkrol)'s comment. I thought he meant getting an error under
--noImpclitAny --checkJswhich is expected.. but looking at the code again, it is disabled for--noImplcitAny, and that is a bug and should be fixed. apologies for the miss understanding.mhegazy commentedon Nov 22, 2017
#20232 should fix that.
gerges-zz commentedon Dec 1, 2017
Just ran into this as well, just so I'm understanding, with #20232 this fix should work for an incrementally converted codebase when using a non TS React component inside of a TSX component with noImplicitAny enabled
vkrol commentedon Dec 3, 2017
Mohamed Hegazy (@mhegazy) Wesley Wigham (@weswigham) it is works in the latest nightly build. Thanks!
danantal commentedon Jan 17, 2018
I ran into this as well.. while using
react-selectwith latest typings. Has this issue been fixed in TS2.6.2?ssunday commentedon Feb 6, 2018
Dan Antal (@danantal) Running into this as well. Not on TS
2.6.2, though. I would upgrade, but it's a massive jump for the codebase.Add temp workaround for microsoft/TypeScript#14558
Legg til ekspanderbart nedtrekkspanel for visittkort
devharf2310 commentedon May 2, 2018
This works for me: