#Problem with type resolution on monorepo

25 messages · Page 1 of 1 (latest)

nimble tapir
#

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 Prayge

#

forgot to include, when I say that the type has been lost, I mean this

#

there's no specified type for it, and line 7 should error or at least warn since it's unreachable code

#

it's set as type any in my case

nimble tapir
#

!helper

oak daggerBOT
#

:warning: Please wait a bit longer. You can ping helpers <t:1674247756:R>.

nimble tapir
nimble tapir
#

!helper

nimble rampart
#

Imported identifiers sometimes lack types in tooltips

#

Are you sure it's actually any typed?

#

I.e can you assign it to a const x: string = Test?

nimble tapir
#

it's not assignable to its actual type nor to other type

#

also this just popped up, maybe after webstorm cached the project again or something

nimble rampart
#

ah, can you try with vscode? webstorm is known to have strange typescript issues on occasion

#

they apply their own secret sauce, that sometimes causes issues

nimble tapir
#

yeah I've seen those as well, jetbrains' ides bugs are uncommon, but when they do happen they're really annoying

nimble rampart
#

if you don't export default, but instead do a named export

#

do you still have the weird import type?

nimble tapir
#

I'll just drop this and stick with nx for the time being