I developed a React application using Typescript and here is the tsconfig file I used in my project. I have no issues with importing the defaults properly as all my files include import React from 'react'
.
{
"compilerOptions": {
"baseUrl": ".",
"module": "esnext",
"moduleResolution": "node",
"outDir": "./dist/",
"target": "es2016",
"jsx": "react",
"allowJs": true,
"experimentalDecorators": true,
"sourceMap": true,
"noUnusedLocals": true,
"types": ["jest"],
"allowSyntheticDefaultImports": true,
"paths": {
"protractor": ["integration-tests/protractor.d.ts"]
},
},
"exclude": [".yarn", "**/node_modules", "dist"],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.json"]
}
However, when running unit tests with Jest, I encountered an issue where Jest complained about the defaults being undefined. I am using ts-jest for transformation. Is there any configuration missing in Jest to recognize the defaults in a standard ES6 way?
To clarify, while I can import using import * as React from 'react'
, my preference is to use the standard ES6 import syntax like import React from 'react'
instead of the typescript way.