I'm trying to setup a simple monorepo with pnpm and I managed to get the imports to work, however when importing objects the type of them is not imported as well. For now I only have two packages setup, one of which (core) is meant to be imported by the other (nyx).
Here's my setup:
./tsconfig.base.json
{
"baseUrl": ".",
"compilerOptions": {
"moduleResolution": "node",
"module": "esnext",
"target": "esnext",
"resolveJsonModule": true,
"esModuleInterop": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": true,
"noImplicitOverride": true,
"importsNotUsedAsValues": "error",
"skipLibCheck": true
},
"exclude": ["dist", "node_modules", "**/*.spec.ts"],
}
Core:
packages/core/package.json
{
"name": "core",
"version": "1.0.0",
"type": "module",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"devDependencies": {
"@types/jest": "29.2.5",
"jest": "29.3.1",
"ts-jest": "29.0.5",
"typescript": "4.9.3"
}
}
packages/core/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"outDir": "dist"
},
"include": [
"."
],
}
Nyx:
packages/nyx/package.json
{
"name": "nyx",
"version": "1.0.0",
"engines": {
"node": ">=16.6.0"
},
"devDependencies": {
"core": "workspace:*",
"@types/jest": "29.2.5",
"jest": "29.3.1",
"ts-jest": "29.0.5",
"typescript": "4.9.3"
}
}
packages/nyx/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
},
"include": [
"src"
]
}
Now, there's a packages/core/src/Test.ts file which I'm using for testing:
const Test: boolean = true
export default Test;
and it's exported via packages/core/src/index.ts with: export * from './Test.js';
I can import it from nyx via import Test from 'core';, however the type of it seems to have been lost. I'd appreciate if anyone can help me with this, preferably without the use of a third party like lerna or turborepo 