Usage of ... and lodash makes typescript output js file without import and causes undefined error
See original GitHub issueGet this repository: https://github.com/bhouser/jestReactMockTsx
In typescript subdirectory, do:
npm install --save-dev lodash @types/lodash
Replace ParentComponent.tsx with this content:
import * as React from 'react';
import ChildComponent from './ChildComponent';
import * as _ from 'lodash';
function x() {
return { ..._.isNil };
}
export default function ParentComponent() {
return (
<div
{ ...x() }
>
<div className="parentComponent">
<ChildComponent />;
</div>
</div>
);
}
You will see that usage of { ..._.isNil }
makes the transformed source to omit the require for ChildComponent.
When you compile the project with tsc
, it does it correctly.
I was using this in a real project and it was working. It was abandoned and when I get it again it was full of upgrade issues with react and react-router. After all updates, I’m having this problem.
I tried to downgrade typescript but I still see this with ts-jest.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Correct way to import lodash - Stack Overflow
js in the root of the regular 'lodash' package, and import has from 'lodash/has' (or const has = require ('lodash/has ) will load...
Read more >TSConfig Option: esModuleInterop - TypeScript
This mis-match causes these two issues: the ES6 modules spec states that a namespace import ( import * as x ) can only...
Read more >External Module Usage Case - Cocos Creator
The biggest problem with how to use npm in Cocos Creator 3.x is the ... package comes with a TypeScript declaration file, which...
Read more >Externals - webpack
js indicates that the module jquery in import $ from 'jquery' should be excluded from bundling. In order to replace this module, the...
Read more >Working with JavaScript in Visual Studio Code
Using the TypeScript language service, VS Code can provide smart ... most JavaScript projects without any configuration, you can make IntelliSense even more ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@asfernandes I just tried this with
typescript@2.4.0-dev.20170504
and it passed the test.@asfernandes please try
typescript@2.4.0-dev.20170504