Во-первых, спасибо за вашу помощь в этом. Я сталкиваюсь с проблемами с изменением компилятора машинописи для репозитория с TS C на webpack w / babel. Я сделал этот пример репозитория, чтобы попытаться решить проблему в более ограниченной области, чем обширный проект машинописного текста, но все же я сталкиваюсь с проблемами.
https://github.com/Falieson/ts-module-webpack-babel-example/pull/1
{
"message": "_local_ts_module_example__WEBPACK_IMPORTED_MODULE_0__.CreateCat is not a constructor",
"stack": "TypeError: _local_ts_module_example__WEBPACK_IMPORTED_MODULE_0__.CreateCat is not a constructor\n at App.eval (webpack-internal:///./App.tsx:238:33)\n at step (webpack-internal:///./App.tsx:170:19)\n at Object.eval [as next] (webpack-internal:///./App.tsx:100:14)\n at eval (webpack-internal:///./App.tsx:72:67)\n at new Promise (<anonymous>)\n at __awaiter (webpack-internal:///./App.tsx:51:10)\n at App.componentDidMount (webpack-internal:///./App.tsx:212:12)\n at App.eval (webpack-internal:///../node_modules/react-hot-loader/dist/react-hot-loader.development.js:704:123)\n at commitLifeCycles (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:19847:22)\n at commitLayoutEffects (webpack-internal:///../node_modules/react-dom/cjs/react-dom.development.js:22834:7)"
}
Вот часть кода:
// CreateCat.ts
// import { Cat } from './Cat.types'
export default class CreateCat {
data = {
hair: true,
eyes: ["green", "blue"],
legs: 4,
tailLength: 50,
bodyLength: 70,
headLength: 10,
}
}
// CreateCat.ts
// workaround for export type {Cat} from './Cat.types'
import {Cat as tsdCat} from './Cat.types'
export type Cat = tsdCat
export {default as CreateCat} from './CreateCat'
// example/src/App.tsx
import {CreateCat} from "@local/ts-module-example"
...
async componentDidMount() {
// myOtherCat
let myOtherCatConstruct
try {
myOtherCatConstruct = new CreateCat()
const myOtherCatData = myOtherCatConstruct.data
const myOtherCat = {
data: myOtherCatData,
left: myOtherCatData.eyes[0],
right: myOtherCatData.eyes[1],
}
console.log({myOtherCat})
this.setState({myOtherCat})
} catch (error) {
this.setState({error: {
message: error.message,
stack: error.stack,
}})
}
}